1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfreprd.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
35 #include <dxfreprd.hxx>
38 //------------------DXFBoundingBox--------------------------------------------
41 void DXFBoundingBox::Union(const DXFVector
& rVector
)
53 if (fMinX
>rVector
.fx
) fMinX
=rVector
.fx
;
54 if (fMinY
>rVector
.fy
) fMinY
=rVector
.fy
;
55 if (fMinZ
>rVector
.fz
) fMinZ
=rVector
.fz
;
56 if (fMaxX
<rVector
.fx
) fMaxX
=rVector
.fx
;
57 if (fMaxY
<rVector
.fy
) fMaxY
=rVector
.fy
;
58 if (fMaxZ
<rVector
.fz
) fMaxZ
=rVector
.fz
;
63 //------------------DXFPalette------------------------------------------------
66 DXFPalette::DXFPalette()
68 short i
,j
,nHue
,nNSat
,nVal
,nC
[3],nmax
,nmed
,nmin
;
75 // Farben 0 - 9 (normale Farben)
76 SetColor(0, 0x00, 0x00, 0x00); // eigentlich nie benutzt
77 SetColor(1, 0xff, 0x00, 0x00);
78 SetColor(2, 0xff, 0xff, 0x00);
79 SetColor(3, 0x00, 0xff, 0x00);
80 SetColor(4, 0x00, 0xff, 0xff);
81 SetColor(5, 0x00, 0x00, 0xff);
82 SetColor(6, 0xff, 0x00, 0xff);
83 SetColor(7, 0x0f, 0x0f, 0x0f); // eigentlich weiss ???
84 SetColor(8, 0x80, 0x80, 0x80);
85 SetColor(9, 0xc0, 0xc0, 0xc0);
88 // (Universal-Palette: 24 Farbtoene * 5 Helligkeiten * 2 Saettigungen )
90 for (nHue
=0; nHue
<24; nHue
++) {
91 for (nVal
=5; nVal
>=1; nVal
--) {
92 for (nNSat
=0; nNSat
<2; nNSat
++) {
94 j
=nHue
-(nmax
<<3); if (j
>4) j
=j
-24;
108 for (j
=0; j
<3; j
++) nC
[j
]=(nC
[j
]>>1)+128;
110 for (j
=0; j
<3; j
++) nC
[j
]=nC
[j
]*nVal
/5;
111 SetColor((BYTE
)(i
++),(BYTE
)nC
[0],(BYTE
)nC
[1],(BYTE
)nC
[2]);
116 // Farben 250 - 255 (Grautoenne)
117 for (i
=0; i
<6; i
++) {
119 SetColor((BYTE
)(250+i
),nV
,nV
,nV
);
124 DXFPalette::~DXFPalette()
132 void DXFPalette::SetColor(BYTE nIndex
, BYTE nRed
, BYTE nGreen
, BYTE nBlue
)
135 pGreen
[nIndex
]=nGreen
;
140 //------------------DXFRepresentation-----------------------------------------
143 DXFRepresentation::DXFRepresentation()
145 setTextEncoding(RTL_TEXTENCODING_IBM_437
);
146 setGlobalLineTypeScale(1.0);
150 DXFRepresentation::~DXFRepresentation()
155 BOOL
DXFRepresentation::Read( SvStream
& rIStream
, USHORT nMinPercent
, USHORT nMaxPercent
)
157 DXFGroupReader
* pDGR
;
164 pDGR
= new DXFGroupReader( rIStream
, nMinPercent
, nMaxPercent
);
167 while (pDGR
->GetG()!=0 || strcmp(pDGR
->GetS(),"EOF")!=0) {
168 if (pDGR
->GetG()==0 && strcmp(pDGR
->GetS(),"SECTION")==0) {
169 if (pDGR
->Read()!=2) {
173 if (strcmp(pDGR
->GetS(),"HEADER" )==0) ReadHeader(*pDGR
);
174 else if (strcmp(pDGR
->GetS(),"TABLES" )==0) aTables
.Read(*pDGR
);
175 else if (strcmp(pDGR
->GetS(),"BLOCKS" )==0) aBlocks
.Read(*pDGR
);
176 else if (strcmp(pDGR
->GetS(),"ENTITIES")==0) aEntities
.Read(*pDGR
);
182 bRes
=pDGR
->GetStatus();
186 if (bRes
==TRUE
&& aBoundingBox
.bEmpty
==TRUE
)
187 CalcBoundingBox(aEntities
,aBoundingBox
);
193 void DXFRepresentation::ReadHeader(DXFGroupReader
& rDGR
)
196 while (rDGR
.GetG()!=0 || (strcmp(rDGR
.GetS(),"EOF")!=0 && strcmp(rDGR
.GetS(),"ENDSEC")!=0) )
198 if (rDGR
.GetG()==9) {
199 if (strcmp(rDGR
.GetS(),"$EXTMIN")==0 ||
200 strcmp(rDGR
.GetS(),"$EXTMAX")==0)
208 } while (rDGR
.GetG()!=9 && rDGR
.GetG()!=0);
209 aVector
.fx
=rDGR
.GetF(10);
210 aVector
.fy
=rDGR
.GetF(20);
211 aVector
.fz
=rDGR
.GetF(30);
212 aBoundingBox
.Union(aVector
);
214 if (strcmp(rDGR
.GetS(),"$DWGCODEPAGE")==0)
218 // FIXME: we really need a whole table of
219 // $DWGCODEPAGE to encodings mappings
220 if ( (strcmp(rDGR
.GetS(),"ANSI_932")==0) ||
221 (strcmp(rDGR
.GetS(),"ansi_932")==0) ||
222 (strcmp(rDGR
.GetS(),"DOS932")==0) ||
223 (strcmp(rDGR
.GetS(),"dos932")==0) )
225 setTextEncoding(RTL_TEXTENCODING_MS_932
);
228 else if (strcmp(rDGR
.GetS(),"$LTSCALE")==0)
231 setGlobalLineTypeScale(getGlobalLineTypeScale() * rDGR
.GetF());
241 void DXFRepresentation::CalcBoundingBox(const DXFEntities
& rEntities
,
242 DXFBoundingBox
& rBox
)
244 DXFBasicEntity
* pBE
=rEntities
.pFirst
;
246 switch (pBE
->eType
) {
248 const DXFLineEntity
* pE
= (DXFLineEntity
*)pBE
;
254 const DXFPointEntity
* pE
= (DXFPointEntity
*)pBE
;
259 const DXFCircleEntity
* pE
= (DXFCircleEntity
*)pBE
;
272 const DXFArcEntity
* pE
= (DXFArcEntity
*)pBE
;
285 const DXFTraceEntity
* pE
= (DXFTraceEntity
*)pBE
;
293 const DXFSolidEntity
* pE
= (DXFSolidEntity
*)pBE
;
301 //const DXFTextEntity * pE = (DXFTextEntity*)pBE;
306 //const DXFShapeEntity * pE = (DXFShapeEntity*)pBE;
311 const DXFInsertEntity
* pE
= (DXFInsertEntity
*)pBE
;
315 pB
=aBlocks
.Search(pE
->sName
);
317 CalcBoundingBox(*pB
,aBox
);
318 if (aBox
.bEmpty
==TRUE
) break;
319 aP
.fx
=(aBox
.fMinX
-pB
->aBasePoint
.fx
)*pE
->fXScale
+pE
->aP0
.fx
;
320 aP
.fy
=(aBox
.fMinY
-pB
->aBasePoint
.fy
)*pE
->fYScale
+pE
->aP0
.fy
;
321 aP
.fz
=(aBox
.fMinZ
-pB
->aBasePoint
.fz
)*pE
->fZScale
+pE
->aP0
.fz
;
323 aP
.fx
=(aBox
.fMaxX
-pB
->aBasePoint
.fx
)*pE
->fXScale
+pE
->aP0
.fx
;
324 aP
.fy
=(aBox
.fMaxY
-pB
->aBasePoint
.fy
)*pE
->fYScale
+pE
->aP0
.fy
;
325 aP
.fz
=(aBox
.fMaxZ
-pB
->aBasePoint
.fz
)*pE
->fZScale
+pE
->aP0
.fz
;
330 //const DXFAttDefEntity * pE = (DXFAttDefEntity*)pBE;
335 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
340 const DXFVertexEntity
* pE
= (DXFVertexEntity
*)pBE
;
345 const DXF3DFaceEntity
* pE
= (DXF3DFaceEntity
*)pBE
;
352 case DXF_DIMENSION
: {
353 const DXFDimensionEntity
* pE
= (DXFDimensionEntity
*)pBE
;
357 pB
=aBlocks
.Search(pE
->sPseudoBlock
);
359 CalcBoundingBox(*pB
,aBox
);
360 if (aBox
.bEmpty
==TRUE
) break;
361 aP
.fx
=aBox
.fMinX
-pB
->aBasePoint
.fx
;
362 aP
.fy
=aBox
.fMinY
-pB
->aBasePoint
.fy
;
363 aP
.fz
=aBox
.fMinZ
-pB
->aBasePoint
.fz
;
365 aP
.fx
=aBox
.fMaxX
-pB
->aBasePoint
.fx
;
366 aP
.fy
=aBox
.fMaxY
-pB
->aBasePoint
.fy
;
367 aP
.fz
=aBox
.fMaxZ
-pB
->aBasePoint
.fz
;
372 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
377 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
383 case DXF_LWPOLYLINE
: