Update ooo320-m1
[ooovba.git] / goodies / source / filter.vcl / idxf / dxfreprd.cxx
blob0ec3d3f556767ec89c1a5e2190752bfa1d3fe0e3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfreprd.cxx,v $
10 * $Revision: 1.9 $
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"
34 #include <string.h>
35 #include <dxfreprd.hxx>
38 //------------------DXFBoundingBox--------------------------------------------
41 void DXFBoundingBox::Union(const DXFVector & rVector)
43 if (bEmpty==TRUE) {
44 fMinX=rVector.fx;
45 fMinY=rVector.fy;
46 fMinZ=rVector.fz;
47 fMaxX=rVector.fx;
48 fMaxY=rVector.fy;
49 fMaxZ=rVector.fz;
50 bEmpty=FALSE;
52 else {
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;
69 BYTE nV;
71 pRed =new BYTE[256];
72 pGreen=new BYTE[256];
73 pBlue =new BYTE[256];
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);
87 // Farben 10 - 249
88 // (Universal-Palette: 24 Farbtoene * 5 Helligkeiten * 2 Saettigungen )
89 i=10;
90 for (nHue=0; nHue<24; nHue++) {
91 for (nVal=5; nVal>=1; nVal--) {
92 for (nNSat=0; nNSat<2; nNSat++) {
93 nmax=((nHue+3)>>3)%3;
94 j=nHue-(nmax<<3); if (j>4) j=j-24;
95 if (j>=0) {
96 nmed=(nmax+1)%3;
97 nmin=(nmax+2)%3;
99 else {
100 nmed=(nmax+2)%3;
101 nmin=(nmax+1)%3;
102 j=-j;
104 nC[nmin]=0;
105 nC[nmed]=255*j/4;
106 nC[nmax]=255;
107 if (nNSat!=0) {
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++) {
118 nV=(BYTE)(i*38+65);
119 SetColor((BYTE)(250+i),nV,nV,nV);
124 DXFPalette::~DXFPalette()
126 delete[] pBlue;
127 delete[] pGreen;
128 delete[] pRed;
132 void DXFPalette::SetColor(BYTE nIndex, BYTE nRed, BYTE nGreen, BYTE nBlue)
134 pRed[nIndex]=nRed;
135 pGreen[nIndex]=nGreen;
136 pBlue[nIndex]=nBlue;
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;
158 BOOL bRes;
160 aTables.Clear();
161 aBlocks.Clear();
162 aEntities.Clear();
164 pDGR = new DXFGroupReader( rIStream, nMinPercent, nMaxPercent );
166 pDGR->Read();
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) {
170 pDGR->SetError();
171 break;
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);
177 else pDGR->Read();
179 else pDGR->Read();
182 bRes=pDGR->GetStatus();
184 delete pDGR;
186 if (bRes==TRUE && aBoundingBox.bEmpty==TRUE)
187 CalcBoundingBox(aEntities,aBoundingBox);
189 return bRes;
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)
202 DXFVector aVector;
203 rDGR.SetF(10,0.0);
204 rDGR.SetF(20,0.0);
205 rDGR.SetF(30,0.0);
206 do {
207 rDGR.Read();
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);
213 } else {
214 if (strcmp(rDGR.GetS(),"$DWGCODEPAGE")==0)
216 rDGR.Read();
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)
230 rDGR.Read();
231 setGlobalLineTypeScale(getGlobalLineTypeScale() * rDGR.GetF());
233 else rDGR.Read();
236 else rDGR.Read();
241 void DXFRepresentation::CalcBoundingBox(const DXFEntities & rEntities,
242 DXFBoundingBox & rBox)
244 DXFBasicEntity * pBE=rEntities.pFirst;
245 while (pBE!=NULL) {
246 switch (pBE->eType) {
247 case DXF_LINE: {
248 const DXFLineEntity * pE = (DXFLineEntity*)pBE;
249 rBox.Union(pE->aP0);
250 rBox.Union(pE->aP1);
251 break;
253 case DXF_POINT: {
254 const DXFPointEntity * pE = (DXFPointEntity*)pBE;
255 rBox.Union(pE->aP0);
256 break;
258 case DXF_CIRCLE: {
259 const DXFCircleEntity * pE = (DXFCircleEntity*)pBE;
260 DXFVector aP;
261 aP=pE->aP0;
262 aP.fx-=pE->fRadius;
263 aP.fy-=pE->fRadius;
264 rBox.Union(aP);
265 aP=pE->aP0;
266 aP.fx+=pE->fRadius;
267 aP.fy+=pE->fRadius;
268 rBox.Union(aP);
269 break;
271 case DXF_ARC: {
272 const DXFArcEntity * pE = (DXFArcEntity*)pBE;
273 DXFVector aP;
274 aP=pE->aP0;
275 aP.fx-=pE->fRadius;
276 aP.fy-=pE->fRadius;
277 rBox.Union(aP);
278 aP=pE->aP0;
279 aP.fx+=pE->fRadius;
280 aP.fy+=pE->fRadius;
281 rBox.Union(aP);
282 break;
284 case DXF_TRACE: {
285 const DXFTraceEntity * pE = (DXFTraceEntity*)pBE;
286 rBox.Union(pE->aP0);
287 rBox.Union(pE->aP1);
288 rBox.Union(pE->aP2);
289 rBox.Union(pE->aP3);
290 break;
292 case DXF_SOLID: {
293 const DXFSolidEntity * pE = (DXFSolidEntity*)pBE;
294 rBox.Union(pE->aP0);
295 rBox.Union(pE->aP1);
296 rBox.Union(pE->aP2);
297 rBox.Union(pE->aP3);
298 break;
300 case DXF_TEXT: {
301 //const DXFTextEntity * pE = (DXFTextEntity*)pBE;
302 //???
303 break;
305 case DXF_SHAPE: {
306 //const DXFShapeEntity * pE = (DXFShapeEntity*)pBE;
307 //???
308 break;
310 case DXF_INSERT: {
311 const DXFInsertEntity * pE = (DXFInsertEntity*)pBE;
312 DXFBlock * pB;
313 DXFBoundingBox aBox;
314 DXFVector aP;
315 pB=aBlocks.Search(pE->sName);
316 if (pB==NULL) break;
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;
322 rBox.Union(aP);
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;
326 rBox.Union(aP);
327 break;
329 case DXF_ATTDEF: {
330 //const DXFAttDefEntity * pE = (DXFAttDefEntity*)pBE;
331 //???
332 break;
334 case DXF_ATTRIB: {
335 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
336 //???
337 break;
339 case DXF_VERTEX: {
340 const DXFVertexEntity * pE = (DXFVertexEntity*)pBE;
341 rBox.Union(pE->aP0);
342 break;
344 case DXF_3DFACE: {
345 const DXF3DFaceEntity * pE = (DXF3DFaceEntity*)pBE;
346 rBox.Union(pE->aP0);
347 rBox.Union(pE->aP1);
348 rBox.Union(pE->aP2);
349 rBox.Union(pE->aP3);
350 break;
352 case DXF_DIMENSION: {
353 const DXFDimensionEntity * pE = (DXFDimensionEntity*)pBE;
354 DXFBlock * pB;
355 DXFBoundingBox aBox;
356 DXFVector aP;
357 pB=aBlocks.Search(pE->sPseudoBlock);
358 if (pB==NULL) break;
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;
364 rBox.Union(aP);
365 aP.fx=aBox.fMaxX-pB->aBasePoint.fx;
366 aP.fy=aBox.fMaxY-pB->aBasePoint.fy;
367 aP.fz=aBox.fMaxZ-pB->aBasePoint.fz;
368 rBox.Union(aP);
369 break;
371 case DXF_POLYLINE: {
372 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
373 //???
374 break;
376 case DXF_SEQEND: {
377 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
378 //???
379 break;
381 case DXF_HATCH :
382 break;
383 case DXF_LWPOLYLINE :
384 break;
386 pBE=pBE->pSucc;