1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <GEOMAlgo_ShapeInfo.hxx>
22 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType);
24 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS);
26 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC);
28 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB);
30 void DumpKindOfName(const GEOMAlgo_KindOfName aKS);
32 void DumpPosition(const gp_Ax3& aAx3);
34 void DumpLocation(const gp_Pnt& aP);
36 void DumpDirection(const gp_Dir& aD);
37 //=======================================================================
40 //=======================================================================
41 GEOMAlgo_ShapeInfo::GEOMAlgo_ShapeInfo()
45 //=======================================================================
48 //=======================================================================
49 GEOMAlgo_ShapeInfo::~GEOMAlgo_ShapeInfo()
52 //=======================================================================
55 //=======================================================================
56 void GEOMAlgo_ShapeInfo::Reset()
63 for (i=0; i<myNbTypes; ++i) {
67 myKindOfShape=GEOMAlgo_KS_UNKNOWN;
68 myKindOfBounds=GEOMAlgo_KB_UNKNOWN;
69 myKindOfClosed=GEOMAlgo_KC_UNKNOWN;
70 myKindOfName=GEOMAlgo_KN_UNKNOWN;
72 myLocation.SetCoord(99., 99., 99.);
73 myDirection.SetCoord(1.,0.,0.);
81 //=======================================================================
84 //=======================================================================
85 void GEOMAlgo_ShapeInfo::SetType(const TopAbs_ShapeEnum aType)
89 //=======================================================================
92 //=======================================================================
93 TopAbs_ShapeEnum GEOMAlgo_ShapeInfo::Type() const
97 //=======================================================================
98 //function : SetNbSubShapes
100 //=======================================================================
101 void GEOMAlgo_ShapeInfo::SetNbSubShapes(const TopAbs_ShapeEnum aType,
102 const Standard_Integer aNb)
106 iN=TypeToInteger(aType);
107 if (iN>=0 && iN<myNbTypes) {
108 myNbSubShapes[iN]=aNb;
111 //=======================================================================
112 //function : NbSubShapes
114 //=======================================================================
115 Standard_Integer GEOMAlgo_ShapeInfo::NbSubShapes(const TopAbs_ShapeEnum aType) const
119 iN=TypeToInteger(aType);
120 if (iN>=0 && iN<myNbTypes) {
121 return myNbSubShapes[iN];
125 //=======================================================================
126 //function : SetKindOfShape
128 //=======================================================================
129 void GEOMAlgo_ShapeInfo::SetKindOfShape(const GEOMAlgo_KindOfShape aT)
133 //=======================================================================
134 //function : KindOfShape
136 //=======================================================================
137 GEOMAlgo_KindOfShape GEOMAlgo_ShapeInfo::KindOfShape() const
139 return myKindOfShape;
141 //=======================================================================
142 //function : SetKindOfName
144 //=======================================================================
145 void GEOMAlgo_ShapeInfo::SetKindOfName(const GEOMAlgo_KindOfName aT)
149 //=======================================================================
150 //function : KindOfName
152 //=======================================================================
153 GEOMAlgo_KindOfName GEOMAlgo_ShapeInfo::KindOfName() const
157 //=======================================================================
158 //function : SetKindOfBounds
160 //=======================================================================
161 void GEOMAlgo_ShapeInfo::SetKindOfBounds(const GEOMAlgo_KindOfBounds aT)
165 //=======================================================================
166 //function : KindOfBounds
168 //=======================================================================
169 GEOMAlgo_KindOfBounds GEOMAlgo_ShapeInfo::KindOfBounds() const
171 return myKindOfBounds;
173 //=======================================================================
174 //function : SetKindOfClosed
176 //=======================================================================
177 void GEOMAlgo_ShapeInfo::SetKindOfClosed(const GEOMAlgo_KindOfClosed aT)
181 //=======================================================================
182 //function : KindOfClosed
184 //=======================================================================
185 GEOMAlgo_KindOfClosed GEOMAlgo_ShapeInfo::KindOfClosed() const
187 return myKindOfClosed;
189 //=======================================================================
190 //function : SetLocation
192 //=======================================================================
193 void GEOMAlgo_ShapeInfo::SetLocation(const gp_Pnt& aP)
197 //=======================================================================
198 //function : Location
200 //=======================================================================
201 const gp_Pnt& GEOMAlgo_ShapeInfo::Location() const
205 //=======================================================================
206 //function : SetDirection
208 //=======================================================================
209 void GEOMAlgo_ShapeInfo::SetDirection(const gp_Dir& aD)
213 //=======================================================================
214 //function : Direction
216 //=======================================================================
217 const gp_Dir& GEOMAlgo_ShapeInfo::Direction() const
221 //=======================================================================
222 //function : SetPosition
224 //=======================================================================
225 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax2& aAx2)
230 //=======================================================================
231 //function : SetPosition
233 //=======================================================================
234 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax3& aAx3)
238 //=======================================================================
239 //function : Position
241 //=======================================================================
242 const gp_Ax3& GEOMAlgo_ShapeInfo::Position() const
247 //=======================================================================
250 //=======================================================================
251 void GEOMAlgo_ShapeInfo::SetPnt1(const gp_Pnt& aP)
255 //=======================================================================
258 //=======================================================================
259 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt1() const
263 //=======================================================================
266 //=======================================================================
267 void GEOMAlgo_ShapeInfo::SetPnt2(const gp_Pnt& aP)
271 //=======================================================================
274 //=======================================================================
275 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt2() const
279 //=======================================================================
280 //function : SetRadius1
282 //=======================================================================
283 void GEOMAlgo_ShapeInfo::SetRadius1(const Standard_Real aR)
287 //=======================================================================
290 //=======================================================================
291 Standard_Real GEOMAlgo_ShapeInfo::Radius1() const
295 //=======================================================================
296 //function : SetRadius2
298 //=======================================================================
299 void GEOMAlgo_ShapeInfo::SetRadius2(const Standard_Real aR)
303 //=======================================================================
306 //=======================================================================
307 Standard_Real GEOMAlgo_ShapeInfo::Radius2() const
311 //=======================================================================
312 //function : SetLength
314 //=======================================================================
315 void GEOMAlgo_ShapeInfo::SetLength(const Standard_Real aL)
319 //=======================================================================
322 //=======================================================================
323 Standard_Real GEOMAlgo_ShapeInfo::Length() const
327 //=======================================================================
328 //function : SetWidth
330 //=======================================================================
331 void GEOMAlgo_ShapeInfo::SetWidth(const Standard_Real aW)
335 //=======================================================================
338 //=======================================================================
339 Standard_Real GEOMAlgo_ShapeInfo::Width() const
343 //=======================================================================
344 //function : SetHeight
346 //=======================================================================
347 void GEOMAlgo_ShapeInfo::SetHeight(const Standard_Real aH)
351 //=======================================================================
354 //=======================================================================
355 Standard_Real GEOMAlgo_ShapeInfo::Height() const
359 //=======================================================================
360 //function : TypeToInteger
362 //=======================================================================
363 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType)
367 iN=(Standard_Integer)aType;
370 //=======================================================================
373 //=======================================================================
374 void GEOMAlgo_ShapeInfo::Dump()const
402 case TopAbs_COMPSOLID:
406 case TopAbs_COMPOUND:
411 printf(" * not implememted yet\n");
415 //=======================================================================
416 //function : DumpCompound
418 //=======================================================================
419 void GEOMAlgo_ShapeInfo::DumpCompound()const
421 Standard_Integer aNbV, aNbE, aNbF, aNbS, aNbC, aNbP;
422 GEOMAlgo_KindOfShape aKS;
423 GEOMAlgo_KindOfName aKN;
424 GEOMAlgo_KindOfBounds aKB;
425 GEOMAlgo_KindOfClosed aKC;
427 aNbV=NbSubShapes(TopAbs_VERTEX);
428 aNbE=NbSubShapes(TopAbs_EDGE);
429 aNbF=NbSubShapes(TopAbs_FACE);
430 aNbS=NbSubShapes(TopAbs_SOLID);
431 aNbC=NbSubShapes(TopAbs_COMPSOLID);
432 aNbP=NbSubShapes(TopAbs_COMPOUND);
438 printf(" *COMPOUND\n");
439 printf(" number of vertices : %d\n", aNbV);
440 printf(" number of edges : %d\n", aNbE);
441 printf(" number of faces : %d\n", aNbF);
442 printf(" number of solids : %d\n", aNbS);
443 printf(" number of compsolids : %d\n", aNbC);
444 printf(" number of compounds : %d\n", aNbP);
445 DumpKindOfShape (aKS);
446 DumpKindOfName (aKN);
447 DumpKindOfBounds(aKB);
448 DumpKindOfClosed(aKC);
450 //=======================================================================
451 //function : DumpCompSolid
453 //=======================================================================
454 void GEOMAlgo_ShapeInfo::DumpCompSolid()const
456 Standard_Integer aNbV, aNbE, aNbF, aNbS;
457 GEOMAlgo_KindOfShape aKS;
458 GEOMAlgo_KindOfName aKN;
459 GEOMAlgo_KindOfBounds aKB;
460 GEOMAlgo_KindOfClosed aKC;
462 aNbV=NbSubShapes(TopAbs_VERTEX);
463 aNbE=NbSubShapes(TopAbs_EDGE);
464 aNbF=NbSubShapes(TopAbs_FACE);
465 aNbS=NbSubShapes(TopAbs_SOLID);
471 printf(" *COMPSOLID\n");
472 printf(" number of vertices: %d\n", aNbV);
473 printf(" number of edges : %d\n", aNbE);
474 printf(" number of faces : %d\n", aNbF);
475 printf(" number of solids : %d\n", aNbS);
476 DumpKindOfShape (aKS);
477 DumpKindOfName (aKN);
478 DumpKindOfBounds(aKB);
479 DumpKindOfClosed(aKC);
482 //=======================================================================
483 //function : DumpSolid
485 //=======================================================================
486 void GEOMAlgo_ShapeInfo::DumpSolid()const
488 Standard_Integer aNbV, aNbE, aNbF;
489 GEOMAlgo_KindOfShape aKS;
490 GEOMAlgo_KindOfName aKN;
491 GEOMAlgo_KindOfBounds aKB;
492 GEOMAlgo_KindOfClosed aKC;
494 aNbV=NbSubShapes(TopAbs_VERTEX);
495 aNbE=NbSubShapes(TopAbs_EDGE);
496 aNbF=NbSubShapes(TopAbs_FACE);
503 printf(" number of vertices: %d\n", aNbV);
504 printf(" number of edges : %d\n", aNbE);
505 printf(" number of faces : %d\n", aNbF);
506 DumpKindOfShape (aKS);
507 DumpKindOfName (aKN);
508 DumpKindOfBounds(aKB);
509 DumpKindOfClosed(aKC);
511 if (aKN==GEOMAlgo_KN_SPHERE) {
512 DumpLocation (myLocation);
513 DumpPosition (myPosition);
514 printf(" Radius1 : %.3lf\n", myRadius1);
516 if (aKN==GEOMAlgo_KN_CYLINDER) {
517 DumpLocation (myLocation);
518 DumpPosition (myPosition);
519 printf(" Radius1 : %.3lf\n", myRadius1);
520 printf(" Height : %.3lf\n", myHeight);
522 else if (aKN==GEOMAlgo_KN_CONE) {
523 DumpLocation (myLocation);
524 DumpPosition (myPosition);
525 printf(" Radius1 : %.3lf\n", myRadius1);
526 printf(" Radius2 : %.3lf\n", myRadius2);
527 printf(" Height : %.3lf\n", myHeight);
529 else if (aKN==GEOMAlgo_KN_TORUS) {
530 DumpLocation (myLocation);
531 DumpPosition (myPosition);
532 printf(" Radius1 : %.3lf\n", myRadius1);
533 printf(" Radius2 : %.3lf\n", myRadius2);
535 else if (aKN==GEOMAlgo_KN_POLYHEDRON) {
536 DumpLocation (myLocation);
537 DumpPosition (myPosition);
539 else if (aKN==GEOMAlgo_KN_BOX) {
540 DumpLocation (myLocation);
541 DumpPosition (myPosition);
542 printf(" Length : %.3lf\n", myLength);
543 printf(" Width : %.3lf\n", myWidth);
544 printf(" Height : %.3lf\n", myHeight);
548 //=======================================================================
549 //function : DumpFace
551 //=======================================================================
552 void GEOMAlgo_ShapeInfo::DumpFace()const
554 Standard_Integer aNbV, aNbE;
555 GEOMAlgo_KindOfShape aKS;
556 GEOMAlgo_KindOfName aKN;
557 GEOMAlgo_KindOfBounds aKB;
558 GEOMAlgo_KindOfClosed aKC;
560 aNbV=NbSubShapes(TopAbs_VERTEX);
561 aNbE=NbSubShapes(TopAbs_EDGE);
568 printf(" number of vertices: %d\n", aNbV);
569 printf(" number of edges : %d\n", aNbE);
570 DumpKindOfShape (aKS);
571 DumpKindOfName (aKN);
572 DumpKindOfBounds(aKB);
573 DumpKindOfClosed(aKC);
576 if (aKN==GEOMAlgo_KN_PLANE) {
577 DumpLocation (myLocation);
578 DumpPosition (myPosition);
580 else if (aKN==GEOMAlgo_KN_DISKCIRCLE) {
581 DumpLocation (myLocation);
582 DumpPosition (myPosition);
583 printf(" Radius1 : %.3lf\n", myRadius1);
585 else if (aKN==GEOMAlgo_KN_DISKELLIPSE) {
586 DumpLocation (myLocation);
587 DumpPosition (myPosition);
588 printf(" Radius1 : %.3lf\n", myRadius1);
589 printf(" Radius2 : %.3lf\n", myRadius2);
591 else if (aKN==GEOMAlgo_KN_RECTANGLE) {
592 DumpLocation (myLocation);
593 DumpPosition (myPosition);
594 printf(" Length : %.3lf\n", myLength);
595 printf(" Width : %.3lf\n", myWidth);
597 else if (aKN==GEOMAlgo_KN_TRIANGLE ||
598 aKN==GEOMAlgo_KN_QUADRANGLE||
599 aKN==GEOMAlgo_KN_POLYGON) {
600 DumpLocation (myLocation);
601 DumpPosition (myPosition);
605 else if (aKN==GEOMAlgo_KN_SPHERE) {
606 DumpLocation (myLocation);
607 DumpPosition (myPosition);
608 printf(" Radius1 : %.3lf", myRadius1);
612 else if (aKN==GEOMAlgo_KN_CYLINDER) {
613 DumpLocation (myLocation);
614 DumpPosition (myPosition);
615 printf(" Radius1 : %.3lf\n", myRadius1);
616 printf(" Height : %.3lf\n", myHeight);
620 else if (aKN==GEOMAlgo_KN_CONE) {
621 DumpLocation (myLocation);
622 DumpPosition (myPosition);
623 printf(" Radius1 : %.3lf\n", myRadius1);
624 printf(" Radius2 : %.3lf\n", myRadius2);
625 printf(" Height : %.3lf\n", myHeight);
629 else if (aKN==GEOMAlgo_KN_TORUS) {
630 DumpLocation (myLocation);
631 DumpPosition (myPosition);
632 printf(" Radius1 : %.3lf\n", myRadius1);
633 printf(" Radius2 : %.3lf\n", myRadius2);
639 //=======================================================================
640 //function : DumpShell
642 //=======================================================================
643 void GEOMAlgo_ShapeInfo::DumpShell()const
645 Standard_Integer aNbV, aNbE, aNbF;
646 GEOMAlgo_KindOfClosed aKC;
650 aNbV=NbSubShapes(TopAbs_VERTEX);
651 aNbE=NbSubShapes(TopAbs_EDGE);
652 aNbF=NbSubShapes(TopAbs_FACE);
653 printf(" number of vertices: %d\n", aNbV);
654 printf(" number of edges : %d\n", aNbE);
655 printf(" number of faces : %d\n", aNbF);
657 DumpKindOfClosed(aKC);
660 //=======================================================================
661 //function : DumpWire
663 //=======================================================================
664 void GEOMAlgo_ShapeInfo::DumpWire()const
666 Standard_Integer aNbV, aNbE;
667 GEOMAlgo_KindOfClosed aKC;
671 aNbV=NbSubShapes(TopAbs_VERTEX);
672 aNbE=NbSubShapes(TopAbs_EDGE);
673 printf(" number of vertices: %d\n", aNbV);
674 printf(" number of edges : %d\n", aNbE);
677 DumpKindOfClosed(aKC);
680 //=======================================================================
681 //function : DumpEdge
683 //=======================================================================
684 void GEOMAlgo_ShapeInfo::DumpEdge()const
686 Standard_Integer aNbV;
687 Standard_Real aX, aY, aZ;
688 GEOMAlgo_KindOfShape aKS;
689 GEOMAlgo_KindOfName aKN;
690 GEOMAlgo_KindOfBounds aKB;
691 GEOMAlgo_KindOfClosed aKC;
693 aNbV=NbSubShapes(TopAbs_VERTEX);
700 printf(" number of vertices: %d\n", aNbV);
701 DumpKindOfShape (aKS);
702 DumpKindOfName (aKN);
703 DumpKindOfBounds(aKB);
704 DumpKindOfClosed(aKC);
707 if (aKN==GEOMAlgo_KN_LINE) {
708 DumpLocation (myLocation);
709 DumpDirection(myDirection);
711 else if (aKN==GEOMAlgo_KN_SEGMENT) {
712 DumpLocation (myLocation);
713 DumpDirection(myDirection);
714 printf(" Length : %.3lf\n", myLength);
715 myPnt1.Coord(aX, aY, aZ);
716 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
717 myPnt2.Coord(aX, aY, aZ);
718 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
721 else if (aKN==GEOMAlgo_KN_CIRCLE) {
722 DumpLocation (myLocation);
723 DumpPosition (myPosition);
724 printf(" Radius1 : %.3lf\n", myRadius1);
726 else if (aKN==GEOMAlgo_KN_ARCCIRCLE) {
727 DumpLocation (myLocation);
728 DumpPosition (myPosition);
729 printf(" Radius1 : %.3lf\n", myRadius1);
730 myPnt1.Coord(aX, aY, aZ);
731 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
732 myPnt2.Coord(aX, aY, aZ);
733 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
735 else if (aKN==GEOMAlgo_KN_ELLIPSE) {
736 DumpLocation (myLocation);
737 DumpPosition (myPosition);
738 printf(" Radius1 : %.3lf\n", myRadius1);
739 printf(" Radius2 : %.3lf\n", myRadius2);
741 else if (aKN==GEOMAlgo_KN_ARCELLIPSE) {
742 DumpLocation (myLocation);
743 DumpPosition (myPosition);
744 printf(" Radius1 : %.3lf\n", myRadius1);
745 printf(" Radius2 : %.3lf\n", myRadius2);
746 myPnt1.Coord(aX, aY, aZ);
747 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
748 myPnt2.Coord(aX, aY, aZ);
749 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
753 //=======================================================================
754 //function : DumpVertex
756 //=======================================================================
757 void GEOMAlgo_ShapeInfo::DumpVertex()const
759 printf(" *VERTEX\n");
760 DumpLocation(myLocation);
762 //=======================================================================
763 //function : DumpLocation
765 //=======================================================================
766 void DumpLocation(const gp_Pnt& aP)
768 Standard_Real aX, aY, aZ;
770 aP.Coord(aX, aY, aZ);
771 printf(" Location : %.3lf %.3lf %.3lf \n", aX, aY, aZ);
773 //=======================================================================
774 //function : DumpDirection
776 //=======================================================================
777 void DumpDirection(const gp_Dir& aD)
779 Standard_Real aX, aY, aZ;
781 aD.Coord(aX, aY, aZ);
782 printf(" Direction: %.3lf %.3lf %.3lf \n", aX, aY, aZ);
784 //=======================================================================
785 //function : DumpPosition
787 //=======================================================================
788 void DumpPosition(const gp_Ax3& aAx3)
790 const gp_Dir& aDZ=aAx3.Axis().Direction();
791 const gp_Dir& aDX=aAx3.XDirection();
792 const gp_Dir& aDY=aAx3.YDirection();
793 printf(" Position:\n");
794 printf(" Axis: %.3lf %.3lf %.3lf \n", aDZ.X(), aDZ.Y(), aDZ.Z());
795 printf(" X : %.3lf %.3lf %.3lf \n", aDX.X(), aDX.Y(), aDX.Z());
796 printf(" Y : %.3lf %.3lf %.3lf \n", aDY.X(), aDY.Y(), aDY.Z());
798 //=======================================================================
799 //function : DumpKindOfBounds
801 //=======================================================================
802 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB)
811 i=(Standard_Integer)aKB;
812 printf(" KindOfBounds: %s\n", pStr[i]);
815 //=======================================================================
816 //function : DumpKindOfClosed
818 //=======================================================================
819 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC)
828 i=(Standard_Integer)aKC;
829 printf(" KindOfClosed: %s\n", pStr[i]);
832 //=======================================================================
833 //function : DumpKindOfShape
835 //=======================================================================
836 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS)
854 i=(Standard_Integer)aKS;
855 printf(" KindOfShape : %s\n", pStr[i]);
857 //=======================================================================
858 //function : DumpKindOfName
860 //=======================================================================
861 void DumpKindOfName(const GEOMAlgo_KindOfName aKS)
887 i=(Standard_Integer)aKS;
888 printf(" KindOfName : %s\n", pStr[i]);