1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <GEOMAlgo_ShapeInfo.ixx>
26 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType);
28 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS);
30 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC);
32 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB);
34 void DumpKindOfName(const GEOMAlgo_KindOfName aKS);
36 void DumpPosition(const gp_Ax3& aAx3);
38 void DumpLocation(const gp_Pnt& aP);
40 void DumpDirection(const gp_Dir& aD);
41 //=======================================================================
44 //=======================================================================
45 GEOMAlgo_ShapeInfo::GEOMAlgo_ShapeInfo()
49 //=======================================================================
52 //=======================================================================
53 GEOMAlgo_ShapeInfo::~GEOMAlgo_ShapeInfo()
56 //=======================================================================
59 //=======================================================================
60 void GEOMAlgo_ShapeInfo::Reset()
67 for (i=0; i<myNbTypes; ++i) {
71 myKindOfShape=GEOMAlgo_KS_UNKNOWN;
72 myKindOfBounds=GEOMAlgo_KB_UNKNOWN;
73 myKindOfClosed=GEOMAlgo_KC_UNKNOWN;
74 myKindOfName=GEOMAlgo_KN_UNKNOWN;
76 myLocation.SetCoord(99., 99., 99.);
77 myDirection.SetCoord(1.,0.,0.);
85 //=======================================================================
88 //=======================================================================
89 void GEOMAlgo_ShapeInfo::SetType(const TopAbs_ShapeEnum aType)
93 //=======================================================================
96 //=======================================================================
97 TopAbs_ShapeEnum GEOMAlgo_ShapeInfo::Type() const
101 //=======================================================================
102 //function : SetNbSubShapes
104 //=======================================================================
105 void GEOMAlgo_ShapeInfo::SetNbSubShapes(const TopAbs_ShapeEnum aType,
106 const Standard_Integer aNb)
110 iN=TypeToInteger(aType);
111 if (iN>=0 && iN<myNbTypes) {
112 myNbSubShapes[iN]=aNb;
115 //=======================================================================
116 //function : NbSubShapes
118 //=======================================================================
119 Standard_Integer GEOMAlgo_ShapeInfo::NbSubShapes(const TopAbs_ShapeEnum aType) const
123 iN=TypeToInteger(aType);
124 if (iN>=0 && iN<myNbTypes) {
125 return myNbSubShapes[iN];
129 //=======================================================================
130 //function : SetKindOfShape
132 //=======================================================================
133 void GEOMAlgo_ShapeInfo::SetKindOfShape(const GEOMAlgo_KindOfShape aT)
137 //=======================================================================
138 //function : KindOfShape
140 //=======================================================================
141 GEOMAlgo_KindOfShape GEOMAlgo_ShapeInfo::KindOfShape() const
143 return myKindOfShape;
145 //=======================================================================
146 //function : SetKindOfName
148 //=======================================================================
149 void GEOMAlgo_ShapeInfo::SetKindOfName(const GEOMAlgo_KindOfName aT)
153 //=======================================================================
154 //function : KindOfName
156 //=======================================================================
157 GEOMAlgo_KindOfName GEOMAlgo_ShapeInfo::KindOfName() const
161 //=======================================================================
162 //function : SetKindOfBounds
164 //=======================================================================
165 void GEOMAlgo_ShapeInfo::SetKindOfBounds(const GEOMAlgo_KindOfBounds aT)
169 //=======================================================================
170 //function : KindOfBounds
172 //=======================================================================
173 GEOMAlgo_KindOfBounds GEOMAlgo_ShapeInfo::KindOfBounds() const
175 return myKindOfBounds;
177 //=======================================================================
178 //function : SetKindOfClosed
180 //=======================================================================
181 void GEOMAlgo_ShapeInfo::SetKindOfClosed(const GEOMAlgo_KindOfClosed aT)
185 //=======================================================================
186 //function : KindOfClosed
188 //=======================================================================
189 GEOMAlgo_KindOfClosed GEOMAlgo_ShapeInfo::KindOfClosed() const
191 return myKindOfClosed;
193 //=======================================================================
194 //function : SetLocation
196 //=======================================================================
197 void GEOMAlgo_ShapeInfo::SetLocation(const gp_Pnt& aP)
201 //=======================================================================
202 //function : Location
204 //=======================================================================
205 const gp_Pnt& GEOMAlgo_ShapeInfo::Location() const
209 //=======================================================================
210 //function : SetDirection
212 //=======================================================================
213 void GEOMAlgo_ShapeInfo::SetDirection(const gp_Dir& aD)
217 //=======================================================================
218 //function : Direction
220 //=======================================================================
221 const gp_Dir& GEOMAlgo_ShapeInfo::Direction() const
225 //=======================================================================
226 //function : SetPosition
228 //=======================================================================
229 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax2& aAx2)
234 //=======================================================================
235 //function : SetPosition
237 //=======================================================================
238 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax3& aAx3)
242 //=======================================================================
243 //function : Position
245 //=======================================================================
246 const gp_Ax3& GEOMAlgo_ShapeInfo::Position() const
251 //=======================================================================
254 //=======================================================================
255 void GEOMAlgo_ShapeInfo::SetPnt1(const gp_Pnt& aP)
259 //=======================================================================
262 //=======================================================================
263 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt1() const
267 //=======================================================================
270 //=======================================================================
271 void GEOMAlgo_ShapeInfo::SetPnt2(const gp_Pnt& aP)
275 //=======================================================================
278 //=======================================================================
279 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt2() const
283 //=======================================================================
284 //function : SetRadius1
286 //=======================================================================
287 void GEOMAlgo_ShapeInfo::SetRadius1(const Standard_Real aR)
291 //=======================================================================
294 //=======================================================================
295 Standard_Real GEOMAlgo_ShapeInfo::Radius1() const
299 //=======================================================================
300 //function : SetRadius2
302 //=======================================================================
303 void GEOMAlgo_ShapeInfo::SetRadius2(const Standard_Real aR)
307 //=======================================================================
310 //=======================================================================
311 Standard_Real GEOMAlgo_ShapeInfo::Radius2() const
315 //=======================================================================
316 //function : SetLength
318 //=======================================================================
319 void GEOMAlgo_ShapeInfo::SetLength(const Standard_Real aL)
323 //=======================================================================
326 //=======================================================================
327 Standard_Real GEOMAlgo_ShapeInfo::Length() const
331 //=======================================================================
332 //function : SetWidth
334 //=======================================================================
335 void GEOMAlgo_ShapeInfo::SetWidth(const Standard_Real aW)
339 //=======================================================================
342 //=======================================================================
343 Standard_Real GEOMAlgo_ShapeInfo::Width() const
347 //=======================================================================
348 //function : SetHeight
350 //=======================================================================
351 void GEOMAlgo_ShapeInfo::SetHeight(const Standard_Real aH)
355 //=======================================================================
358 //=======================================================================
359 Standard_Real GEOMAlgo_ShapeInfo::Height() const
363 //=======================================================================
364 //function : TypeToInteger
366 //=======================================================================
367 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType)
371 iN=(Standard_Integer)aType;
374 //=======================================================================
377 //=======================================================================
378 void GEOMAlgo_ShapeInfo::Dump()const
406 case TopAbs_COMPSOLID:
410 case TopAbs_COMPOUND:
415 printf(" * not implememted yet\n");
419 //=======================================================================
420 //function : DumpCompound
422 //=======================================================================
423 void GEOMAlgo_ShapeInfo::DumpCompound()const
425 Standard_Integer aNbV, aNbE, aNbF, aNbS, aNbC, aNbP;
426 GEOMAlgo_KindOfShape aKS;
427 GEOMAlgo_KindOfName aKN;
428 GEOMAlgo_KindOfBounds aKB;
429 GEOMAlgo_KindOfClosed aKC;
431 aNbV=NbSubShapes(TopAbs_VERTEX);
432 aNbE=NbSubShapes(TopAbs_EDGE);
433 aNbF=NbSubShapes(TopAbs_FACE);
434 aNbS=NbSubShapes(TopAbs_SOLID);
435 aNbC=NbSubShapes(TopAbs_COMPSOLID);
436 aNbP=NbSubShapes(TopAbs_COMPOUND);
442 printf(" *COMPOUND\n");
443 printf(" number of vertices : %d\n", aNbV);
444 printf(" number of edges : %d\n", aNbE);
445 printf(" number of faces : %d\n", aNbF);
446 printf(" number of solids : %d\n", aNbS);
447 printf(" number of compsolids : %d\n", aNbC);
448 printf(" number of compounds : %d\n", aNbP);
449 DumpKindOfShape (aKS);
450 DumpKindOfName (aKN);
451 DumpKindOfBounds(aKB);
452 DumpKindOfClosed(aKC);
454 //=======================================================================
455 //function : DumpCompSolid
457 //=======================================================================
458 void GEOMAlgo_ShapeInfo::DumpCompSolid()const
460 Standard_Integer aNbV, aNbE, aNbF, aNbS;
461 GEOMAlgo_KindOfShape aKS;
462 GEOMAlgo_KindOfName aKN;
463 GEOMAlgo_KindOfBounds aKB;
464 GEOMAlgo_KindOfClosed aKC;
466 aNbV=NbSubShapes(TopAbs_VERTEX);
467 aNbE=NbSubShapes(TopAbs_EDGE);
468 aNbF=NbSubShapes(TopAbs_FACE);
469 aNbS=NbSubShapes(TopAbs_SOLID);
475 printf(" *COMPSOLID\n");
476 printf(" number of vertices: %d\n", aNbV);
477 printf(" number of edges : %d\n", aNbE);
478 printf(" number of faces : %d\n", aNbF);
479 printf(" number of solids : %d\n", aNbS);
480 DumpKindOfShape (aKS);
481 DumpKindOfName (aKN);
482 DumpKindOfBounds(aKB);
483 DumpKindOfClosed(aKC);
486 //=======================================================================
487 //function : DumpSolid
489 //=======================================================================
490 void GEOMAlgo_ShapeInfo::DumpSolid()const
492 Standard_Integer aNbV, aNbE, aNbF;
493 GEOMAlgo_KindOfShape aKS;
494 GEOMAlgo_KindOfName aKN;
495 GEOMAlgo_KindOfBounds aKB;
496 GEOMAlgo_KindOfClosed aKC;
498 aNbV=NbSubShapes(TopAbs_VERTEX);
499 aNbE=NbSubShapes(TopAbs_EDGE);
500 aNbF=NbSubShapes(TopAbs_FACE);
507 printf(" number of vertices: %d\n", aNbV);
508 printf(" number of edges : %d\n", aNbE);
509 printf(" number of faces : %d\n", aNbF);
510 DumpKindOfShape (aKS);
511 DumpKindOfName (aKN);
512 DumpKindOfBounds(aKB);
513 DumpKindOfClosed(aKC);
515 if (aKN==GEOMAlgo_KN_SPHERE) {
516 DumpLocation (myLocation);
517 DumpPosition (myPosition);
518 printf(" Radius1 : %.3lf\n", myRadius1);
520 if (aKN==GEOMAlgo_KN_CYLINDER) {
521 DumpLocation (myLocation);
522 DumpPosition (myPosition);
523 printf(" Radius1 : %.3lf\n", myRadius1);
524 printf(" Height : %.3lf\n", myHeight);
526 else if (aKN==GEOMAlgo_KN_CONE) {
527 DumpLocation (myLocation);
528 DumpPosition (myPosition);
529 printf(" Radius1 : %.3lf\n", myRadius1);
530 printf(" Radius2 : %.3lf\n", myRadius2);
531 printf(" Height : %.3lf\n", myHeight);
533 else if (aKN==GEOMAlgo_KN_TORUS) {
534 DumpLocation (myLocation);
535 DumpPosition (myPosition);
536 printf(" Radius1 : %.3lf\n", myRadius1);
537 printf(" Radius2 : %.3lf\n", myRadius2);
539 else if (aKN==GEOMAlgo_KN_POLYHEDRON) {
540 DumpLocation (myLocation);
541 DumpPosition (myPosition);
543 else if (aKN==GEOMAlgo_KN_BOX) {
544 DumpLocation (myLocation);
545 DumpPosition (myPosition);
546 printf(" Length : %.3lf\n", myLength);
547 printf(" Width : %.3lf\n", myWidth);
548 printf(" Height : %.3lf\n", myHeight);
552 //=======================================================================
553 //function : DumpFace
555 //=======================================================================
556 void GEOMAlgo_ShapeInfo::DumpFace()const
558 Standard_Integer aNbV, aNbE;
559 GEOMAlgo_KindOfShape aKS;
560 GEOMAlgo_KindOfName aKN;
561 GEOMAlgo_KindOfBounds aKB;
562 GEOMAlgo_KindOfClosed aKC;
564 aNbV=NbSubShapes(TopAbs_VERTEX);
565 aNbE=NbSubShapes(TopAbs_EDGE);
572 printf(" number of vertices: %d\n", aNbV);
573 printf(" number of edges : %d\n", aNbE);
574 DumpKindOfShape (aKS);
575 DumpKindOfName (aKN);
576 DumpKindOfBounds(aKB);
577 DumpKindOfClosed(aKC);
580 if (aKN==GEOMAlgo_KN_PLANE) {
581 DumpLocation (myLocation);
582 DumpPosition (myPosition);
584 else if (aKN==GEOMAlgo_KN_DISKCIRCLE) {
585 DumpLocation (myLocation);
586 DumpPosition (myPosition);
587 printf(" Radius1 : %.3lf\n", myRadius1);
589 else if (aKN==GEOMAlgo_KN_DISKELLIPSE) {
590 DumpLocation (myLocation);
591 DumpPosition (myPosition);
592 printf(" Radius1 : %.3lf\n", myRadius1);
593 printf(" Radius2 : %.3lf\n", myRadius2);
595 else if (aKN==GEOMAlgo_KN_RECTANGLE) {
596 DumpLocation (myLocation);
597 DumpPosition (myPosition);
598 printf(" Length : %.3lf\n", myLength);
599 printf(" Width : %.3lf\n", myWidth);
601 else if (aKN==GEOMAlgo_KN_TRIANGLE ||
602 aKN==GEOMAlgo_KN_QUADRANGLE||
603 aKN==GEOMAlgo_KN_POLYGON) {
604 DumpLocation (myLocation);
605 DumpPosition (myPosition);
609 else if (aKN==GEOMAlgo_KN_SPHERE) {
610 DumpLocation (myLocation);
611 DumpPosition (myPosition);
612 printf(" Radius1 : %.3lf", myRadius1);
616 else if (aKN==GEOMAlgo_KN_CYLINDER) {
617 DumpLocation (myLocation);
618 DumpPosition (myPosition);
619 printf(" Radius1 : %.3lf\n", myRadius1);
620 printf(" Height : %.3lf\n", myHeight);
624 else if (aKN==GEOMAlgo_KN_CONE) {
625 DumpLocation (myLocation);
626 DumpPosition (myPosition);
627 printf(" Radius1 : %.3lf\n", myRadius1);
628 printf(" Radius2 : %.3lf\n", myRadius2);
629 printf(" Height : %.3lf\n", myHeight);
633 else if (aKN==GEOMAlgo_KN_TORUS) {
634 DumpLocation (myLocation);
635 DumpPosition (myPosition);
636 printf(" Radius1 : %.3lf\n", myRadius1);
637 printf(" Radius2 : %.3lf\n", myRadius2);
643 //=======================================================================
644 //function : DumpShell
646 //=======================================================================
647 void GEOMAlgo_ShapeInfo::DumpShell()const
649 Standard_Integer aNbV, aNbE, aNbF;
650 GEOMAlgo_KindOfClosed aKC;
654 aNbV=NbSubShapes(TopAbs_VERTEX);
655 aNbE=NbSubShapes(TopAbs_EDGE);
656 aNbF=NbSubShapes(TopAbs_FACE);
657 printf(" number of vertices: %d\n", aNbV);
658 printf(" number of edges : %d\n", aNbE);
659 printf(" number of faces : %d\n", aNbF);
661 DumpKindOfClosed(aKC);
664 //=======================================================================
665 //function : DumpWire
667 //=======================================================================
668 void GEOMAlgo_ShapeInfo::DumpWire()const
670 Standard_Integer aNbV, aNbE;
671 GEOMAlgo_KindOfClosed aKC;
675 aNbV=NbSubShapes(TopAbs_VERTEX);
676 aNbE=NbSubShapes(TopAbs_EDGE);
677 printf(" number of vertices: %d\n", aNbV);
678 printf(" number of edges : %d\n", aNbE);
681 DumpKindOfClosed(aKC);
684 //=======================================================================
685 //function : DumpEdge
687 //=======================================================================
688 void GEOMAlgo_ShapeInfo::DumpEdge()const
690 Standard_Integer aNbV;
691 Standard_Real aX, aY, aZ;
692 GEOMAlgo_KindOfShape aKS;
693 GEOMAlgo_KindOfName aKN;
694 GEOMAlgo_KindOfBounds aKB;
695 GEOMAlgo_KindOfClosed aKC;
697 aNbV=NbSubShapes(TopAbs_VERTEX);
704 printf(" number of vertices: %d\n", aNbV);
705 DumpKindOfShape (aKS);
706 DumpKindOfName (aKN);
707 DumpKindOfBounds(aKB);
708 DumpKindOfClosed(aKC);
711 if (aKN==GEOMAlgo_KN_LINE) {
712 DumpLocation (myLocation);
713 DumpDirection(myDirection);
715 else if (aKN==GEOMAlgo_KN_SEGMENT) {
716 DumpLocation (myLocation);
717 DumpDirection(myDirection);
718 printf(" Length : %.3lf\n", myLength);
719 myPnt1.Coord(aX, aY, aZ);
720 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
721 myPnt2.Coord(aX, aY, aZ);
722 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
725 else if (aKN==GEOMAlgo_KN_CIRCLE) {
726 DumpLocation (myLocation);
727 DumpPosition (myPosition);
728 printf(" Radius1 : %.3lf\n", myRadius1);
730 else if (aKN==GEOMAlgo_KN_ARCCIRCLE) {
731 DumpLocation (myLocation);
732 DumpPosition (myPosition);
733 printf(" Radius1 : %.3lf\n", myRadius1);
734 myPnt1.Coord(aX, aY, aZ);
735 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
736 myPnt2.Coord(aX, aY, aZ);
737 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
739 else if (aKN==GEOMAlgo_KN_ELLIPSE) {
740 DumpLocation (myLocation);
741 DumpPosition (myPosition);
742 printf(" Radius1 : %.3lf\n", myRadius1);
743 printf(" Radius2 : %.3lf\n", myRadius2);
745 else if (aKN==GEOMAlgo_KN_ARCELLIPSE) {
746 DumpLocation (myLocation);
747 DumpPosition (myPosition);
748 printf(" Radius1 : %.3lf\n", myRadius1);
749 printf(" Radius2 : %.3lf\n", myRadius2);
750 myPnt1.Coord(aX, aY, aZ);
751 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
752 myPnt2.Coord(aX, aY, aZ);
753 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
757 //=======================================================================
758 //function : DumpVertex
760 //=======================================================================
761 void GEOMAlgo_ShapeInfo::DumpVertex()const
763 printf(" *VERTEX\n");
764 DumpLocation(myLocation);
766 //=======================================================================
767 //function : DumpLocation
769 //=======================================================================
770 void DumpLocation(const gp_Pnt& aP)
772 Standard_Real aX, aY, aZ;
774 aP.Coord(aX, aY, aZ);
775 printf(" Location : %.3lf %.3lf %.3lf \n", aX, aY, aZ);
777 //=======================================================================
778 //function : DumpDirection
780 //=======================================================================
781 void DumpDirection(const gp_Dir& aD)
783 Standard_Real aX, aY, aZ;
785 aD.Coord(aX, aY, aZ);
786 printf(" Direction: %.3lf %.3lf %.3lf \n", aX, aY, aZ);
788 //=======================================================================
789 //function : DumpPosition
791 //=======================================================================
792 void DumpPosition(const gp_Ax3& aAx3)
794 const gp_Dir& aDZ=aAx3.Axis().Direction();
795 const gp_Dir& aDX=aAx3.XDirection();
796 const gp_Dir& aDY=aAx3.YDirection();
797 printf(" Position:\n");
798 printf(" Axis: %.3lf %.3lf %.3lf \n", aDZ.X(), aDZ.Y(), aDZ.Z());
799 printf(" X : %.3lf %.3lf %.3lf \n", aDX.X(), aDX.Y(), aDX.Z());
800 printf(" Y : %.3lf %.3lf %.3lf \n", aDY.X(), aDY.Y(), aDY.Z());
802 //=======================================================================
803 //function : DumpKindOfBounds
805 //=======================================================================
806 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB)
815 i=(Standard_Integer)aKB;
816 printf(" KindOfBounds: %s\n", pStr[i]);
819 //=======================================================================
820 //function : DumpKindOfClosed
822 //=======================================================================
823 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC)
832 i=(Standard_Integer)aKC;
833 printf(" KindOfClosed: %s\n", pStr[i]);
836 //=======================================================================
837 //function : DumpKindOfShape
839 //=======================================================================
840 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS)
857 i=(Standard_Integer)aKS;
858 printf(" KindOfShape : %s\n", pStr[i]);
860 //=======================================================================
861 //function : DumpKindOfName
863 //=======================================================================
864 void DumpKindOfName(const GEOMAlgo_KindOfName aKS)
890 i=(Standard_Integer)aKS;
891 printf(" KindOfName : %s\n", pStr[i]);