1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
20 #include <GEOMAlgo_ShapeInfo.hxx>
23 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType);
25 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS);
27 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC);
29 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB);
31 void DumpKindOfName(const GEOMAlgo_KindOfName aKS);
33 void DumpKindOfDef(const GEOMAlgo_KindOfDef aKD);
35 void DumpPosition(const gp_Ax3& aAx3);
37 void DumpLocation(const gp_Pnt& aP);
39 void DumpDirection(const gp_Dir& aD);
40 //=======================================================================
43 //=======================================================================
44 GEOMAlgo_ShapeInfo::GEOMAlgo_ShapeInfo()
48 //=======================================================================
51 //=======================================================================
52 GEOMAlgo_ShapeInfo::~GEOMAlgo_ShapeInfo()
55 //=======================================================================
58 //=======================================================================
59 void GEOMAlgo_ShapeInfo::Reset()
66 for (i=0; i<myNbTypes; ++i) {
70 myKindOfShape=GEOMAlgo_KS_UNKNOWN;
71 myKindOfBounds=GEOMAlgo_KB_UNKNOWN;
72 myKindOfClosed=GEOMAlgo_KC_UNKNOWN;
73 myKindOfName=GEOMAlgo_KN_UNKNOWN;
74 myKindOfDef=GEOMAlgo_KD_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
120 (const TopAbs_ShapeEnum aType) const
124 iN=TypeToInteger(aType);
125 if (iN>=0 && iN<myNbTypes) {
126 return myNbSubShapes[iN];
130 //=======================================================================
131 //function : SetKindOfShape
133 //=======================================================================
134 void GEOMAlgo_ShapeInfo::SetKindOfShape(const GEOMAlgo_KindOfShape aT)
138 //=======================================================================
139 //function : KindOfShape
141 //=======================================================================
142 GEOMAlgo_KindOfShape GEOMAlgo_ShapeInfo::KindOfShape() const
144 return myKindOfShape;
146 //=======================================================================
147 //function : SetKindOfName
149 //=======================================================================
150 void GEOMAlgo_ShapeInfo::SetKindOfName(const GEOMAlgo_KindOfName aT)
154 //=======================================================================
155 //function : KindOfName
157 //=======================================================================
158 GEOMAlgo_KindOfName GEOMAlgo_ShapeInfo::KindOfName() const
162 //=======================================================================
163 //function : SetKindOfBounds
165 //=======================================================================
166 void GEOMAlgo_ShapeInfo::SetKindOfBounds(const GEOMAlgo_KindOfBounds aT)
170 //=======================================================================
171 //function : KindOfBounds
173 //=======================================================================
174 GEOMAlgo_KindOfBounds GEOMAlgo_ShapeInfo::KindOfBounds() const
176 return myKindOfBounds;
178 //=======================================================================
179 //function : SetKindOfClosed
181 //=======================================================================
182 void GEOMAlgo_ShapeInfo::SetKindOfClosed(const GEOMAlgo_KindOfClosed aT)
186 //=======================================================================
187 //function : KindOfClosed
189 //=======================================================================
190 GEOMAlgo_KindOfClosed GEOMAlgo_ShapeInfo::KindOfClosed() const
192 return myKindOfClosed;
194 //=======================================================================
195 //function : SetKindOfDef
197 //=======================================================================
198 void GEOMAlgo_ShapeInfo::SetKindOfDef(const GEOMAlgo_KindOfDef aT)
202 //=======================================================================
203 //function : KindOfDef
205 //=======================================================================
206 GEOMAlgo_KindOfDef GEOMAlgo_ShapeInfo::KindOfDef() const
210 //=======================================================================
211 //function : SetLocation
213 //=======================================================================
214 void GEOMAlgo_ShapeInfo::SetLocation(const gp_Pnt& aP)
218 //=======================================================================
219 //function : Location
221 //=======================================================================
222 const gp_Pnt& GEOMAlgo_ShapeInfo::Location() const
226 //=======================================================================
227 //function : SetDirection
229 //=======================================================================
230 void GEOMAlgo_ShapeInfo::SetDirection(const gp_Dir& aD)
234 //=======================================================================
235 //function : Direction
237 //=======================================================================
238 const gp_Dir& GEOMAlgo_ShapeInfo::Direction() const
242 //=======================================================================
243 //function : SetPosition
245 //=======================================================================
246 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax2& aAx2)
251 //=======================================================================
252 //function : SetPosition
254 //=======================================================================
255 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax3& aAx3)
259 //=======================================================================
260 //function : Position
262 //=======================================================================
263 const gp_Ax3& GEOMAlgo_ShapeInfo::Position() const
268 //=======================================================================
271 //=======================================================================
272 void GEOMAlgo_ShapeInfo::SetPnt1(const gp_Pnt& aP)
276 //=======================================================================
279 //=======================================================================
280 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt1() const
284 //=======================================================================
287 //=======================================================================
288 void GEOMAlgo_ShapeInfo::SetPnt2(const gp_Pnt& aP)
292 //=======================================================================
295 //=======================================================================
296 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt2() const
300 //=======================================================================
301 //function : SetRadius1
303 //=======================================================================
304 void GEOMAlgo_ShapeInfo::SetRadius1(const Standard_Real aR)
308 //=======================================================================
311 //=======================================================================
312 Standard_Real GEOMAlgo_ShapeInfo::Radius1() const
316 //=======================================================================
317 //function : SetRadius2
319 //=======================================================================
320 void GEOMAlgo_ShapeInfo::SetRadius2(const Standard_Real aR)
324 //=======================================================================
327 //=======================================================================
328 Standard_Real GEOMAlgo_ShapeInfo::Radius2() const
332 //=======================================================================
333 //function : SetLength
335 //=======================================================================
336 void GEOMAlgo_ShapeInfo::SetLength(const Standard_Real aL)
340 //=======================================================================
343 //=======================================================================
344 Standard_Real GEOMAlgo_ShapeInfo::Length() const
348 //=======================================================================
349 //function : SetWidth
351 //=======================================================================
352 void GEOMAlgo_ShapeInfo::SetWidth(const Standard_Real aW)
356 //=======================================================================
359 //=======================================================================
360 Standard_Real GEOMAlgo_ShapeInfo::Width() const
364 //=======================================================================
365 //function : SetHeight
367 //=======================================================================
368 void GEOMAlgo_ShapeInfo::SetHeight(const Standard_Real aH)
372 //=======================================================================
375 //=======================================================================
376 Standard_Real GEOMAlgo_ShapeInfo::Height() const
380 //=======================================================================
381 //function : TypeToInteger
383 //=======================================================================
384 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType)
388 iN=(Standard_Integer)aType;
391 //=======================================================================
394 //=======================================================================
395 void GEOMAlgo_ShapeInfo::Dump()const
423 case TopAbs_COMPSOLID:
427 case TopAbs_COMPOUND:
432 printf(" * not implemented yet\n");
436 //=======================================================================
437 //function : DumpCompound
439 //=======================================================================
440 void GEOMAlgo_ShapeInfo::DumpCompound()const
442 Standard_Integer aNbV, aNbE, aNbF, aNbS, aNbC, aNbP;
443 GEOMAlgo_KindOfShape aKS;
444 GEOMAlgo_KindOfName aKN;
445 GEOMAlgo_KindOfBounds aKB;
446 GEOMAlgo_KindOfClosed aKC;
448 aNbV=NbSubShapes(TopAbs_VERTEX);
449 aNbE=NbSubShapes(TopAbs_EDGE);
450 aNbF=NbSubShapes(TopAbs_FACE);
451 aNbS=NbSubShapes(TopAbs_SOLID);
452 aNbC=NbSubShapes(TopAbs_COMPSOLID);
453 aNbP=NbSubShapes(TopAbs_COMPOUND);
459 printf(" *COMPOUND\n");
460 printf(" number of vertices : %d\n", aNbV);
461 printf(" number of edges : %d\n", aNbE);
462 printf(" number of faces : %d\n", aNbF);
463 printf(" number of solids : %d\n", aNbS);
464 printf(" number of compsolids : %d\n", aNbC);
465 printf(" number of compounds : %d\n", aNbP);
466 DumpKindOfShape (aKS);
467 DumpKindOfName (aKN);
468 DumpKindOfBounds(aKB);
469 DumpKindOfClosed(aKC);
471 //=======================================================================
472 //function : DumpCompSolid
474 //=======================================================================
475 void GEOMAlgo_ShapeInfo::DumpCompSolid()const
477 Standard_Integer aNbV, aNbE, aNbF, aNbS;
478 GEOMAlgo_KindOfShape aKS;
479 GEOMAlgo_KindOfName aKN;
480 GEOMAlgo_KindOfBounds aKB;
481 GEOMAlgo_KindOfClosed aKC;
483 aNbV=NbSubShapes(TopAbs_VERTEX);
484 aNbE=NbSubShapes(TopAbs_EDGE);
485 aNbF=NbSubShapes(TopAbs_FACE);
486 aNbS=NbSubShapes(TopAbs_SOLID);
492 printf(" *COMPSOLID\n");
493 printf(" number of vertices: %d\n", aNbV);
494 printf(" number of edges : %d\n", aNbE);
495 printf(" number of faces : %d\n", aNbF);
496 printf(" number of solids : %d\n", aNbS);
497 DumpKindOfShape (aKS);
498 DumpKindOfName (aKN);
499 DumpKindOfBounds(aKB);
500 DumpKindOfClosed(aKC);
502 //=======================================================================
503 //function : DumpSolid
505 //=======================================================================
506 void GEOMAlgo_ShapeInfo::DumpSolid()const
508 Standard_Integer aNbV, aNbE, aNbF;
509 GEOMAlgo_KindOfShape aKS;
510 GEOMAlgo_KindOfName aKN;
511 GEOMAlgo_KindOfBounds aKB;
512 GEOMAlgo_KindOfClosed aKC;
514 aNbV=NbSubShapes(TopAbs_VERTEX);
515 aNbE=NbSubShapes(TopAbs_EDGE);
516 aNbF=NbSubShapes(TopAbs_FACE);
523 printf(" number of vertices: %d\n", aNbV);
524 printf(" number of edges : %d\n", aNbE);
525 printf(" number of faces : %d\n", aNbF);
526 DumpKindOfShape (aKS);
527 DumpKindOfName (aKN);
528 DumpKindOfBounds(aKB);
529 DumpKindOfClosed(aKC);
531 if (aKN==GEOMAlgo_KN_SPHERE) {
532 DumpLocation (myLocation);
533 DumpPosition (myPosition);
534 printf(" Radius1 : %.3lf\n", myRadius1);
536 if (aKN==GEOMAlgo_KN_CYLINDER) {
537 DumpLocation (myLocation);
538 DumpPosition (myPosition);
539 printf(" Radius1 : %.3lf\n", myRadius1);
540 printf(" Height : %.3lf\n", myHeight);
542 else if (aKN==GEOMAlgo_KN_CONE) {
543 DumpLocation (myLocation);
544 DumpPosition (myPosition);
545 printf(" Radius1 : %.3lf\n", myRadius1);
546 printf(" Radius2 : %.3lf\n", myRadius2);
547 printf(" Height : %.3lf\n", myHeight);
549 else if (aKN==GEOMAlgo_KN_TORUS) {
550 DumpLocation (myLocation);
551 DumpPosition (myPosition);
552 printf(" Radius1 : %.3lf\n", myRadius1);
553 printf(" Radius2 : %.3lf\n", myRadius2);
555 else if (aKN==GEOMAlgo_KN_POLYHEDRON) {
556 DumpLocation (myLocation);
557 DumpPosition (myPosition);
559 else if (aKN==GEOMAlgo_KN_BOX) {
560 DumpLocation (myLocation);
561 DumpPosition (myPosition);
562 printf(" Length : %.3lf\n", myLength);
563 printf(" Width : %.3lf\n", myWidth);
564 printf(" Height : %.3lf\n", myHeight);
567 //=======================================================================
568 //function : DumpFace
570 //=======================================================================
571 void GEOMAlgo_ShapeInfo::DumpFace()const
573 Standard_Integer aNbV, aNbE;
574 GEOMAlgo_KindOfShape aKS;
575 GEOMAlgo_KindOfName aKN;
576 GEOMAlgo_KindOfBounds aKB;
577 GEOMAlgo_KindOfClosed aKC;
578 GEOMAlgo_KindOfDef aKD;
580 aNbV=NbSubShapes(TopAbs_VERTEX);
581 aNbE=NbSubShapes(TopAbs_EDGE);
589 printf(" number of vertices: %d\n", aNbV);
590 printf(" number of edges : %d\n", aNbE);
591 DumpKindOfShape (aKS);
592 DumpKindOfName (aKN);
593 DumpKindOfBounds(aKB);
594 DumpKindOfClosed(aKC);
598 if (aKN==GEOMAlgo_KN_PLANE) {
599 DumpLocation (myLocation);
600 DumpPosition (myPosition);
602 else if (aKN==GEOMAlgo_KN_DISKCIRCLE) {
603 DumpLocation (myLocation);
604 DumpPosition (myPosition);
605 printf(" Radius1 : %.3lf\n", myRadius1);
607 else if (aKN==GEOMAlgo_KN_DISKELLIPSE) {
608 DumpLocation (myLocation);
609 DumpPosition (myPosition);
610 printf(" Radius1 : %.3lf\n", myRadius1);
611 printf(" Radius2 : %.3lf\n", myRadius2);
613 else if (aKN==GEOMAlgo_KN_RECTANGLE) {
614 DumpLocation (myLocation);
615 DumpPosition (myPosition);
616 printf(" Length : %.3lf\n", myLength);
617 printf(" Width : %.3lf\n", myWidth);
619 else if (aKN==GEOMAlgo_KN_TRIANGLE ||
620 aKN==GEOMAlgo_KN_QUADRANGLE||
621 aKN==GEOMAlgo_KN_POLYGON) {
622 DumpLocation (myLocation);
623 DumpPosition (myPosition);
627 else if (aKN==GEOMAlgo_KN_SPHERE) {
628 DumpLocation (myLocation);
629 DumpPosition (myPosition);
630 printf(" Radius1 : %.3lf", myRadius1);
634 else if (aKN==GEOMAlgo_KN_CYLINDER) {
635 DumpLocation (myLocation);
636 DumpPosition (myPosition);
637 printf(" Radius1 : %.3lf\n", myRadius1);
638 printf(" Height : %.3lf\n", myHeight);
642 else if (aKN==GEOMAlgo_KN_CONE) {
643 DumpLocation (myLocation);
644 DumpPosition (myPosition);
645 printf(" Radius1 : %.3lf\n", myRadius1);
646 printf(" Radius2 : %.3lf\n", myRadius2);
647 printf(" Height : %.3lf\n", myHeight);
651 else if (aKN==GEOMAlgo_KN_TORUS) {
652 DumpLocation (myLocation);
653 DumpPosition (myPosition);
654 printf(" Radius1 : %.3lf\n", myRadius1);
655 printf(" Radius2 : %.3lf\n", myRadius2);
661 //=======================================================================
662 //function : DumpShell
664 //=======================================================================
665 void GEOMAlgo_ShapeInfo::DumpShell()const
667 Standard_Integer aNbV, aNbE, aNbF;
668 GEOMAlgo_KindOfClosed aKC;
672 aNbV=NbSubShapes(TopAbs_VERTEX);
673 aNbE=NbSubShapes(TopAbs_EDGE);
674 aNbF=NbSubShapes(TopAbs_FACE);
675 printf(" number of vertices: %d\n", aNbV);
676 printf(" number of edges : %d\n", aNbE);
677 printf(" number of faces : %d\n", aNbF);
679 DumpKindOfClosed(aKC);
682 //=======================================================================
683 //function : DumpWire
685 //=======================================================================
686 void GEOMAlgo_ShapeInfo::DumpWire()const
688 Standard_Integer aNbV, aNbE;
689 GEOMAlgo_KindOfClosed aKC;
693 aNbV=NbSubShapes(TopAbs_VERTEX);
694 aNbE=NbSubShapes(TopAbs_EDGE);
695 printf(" number of vertices: %d\n", aNbV);
696 printf(" number of edges : %d\n", aNbE);
699 DumpKindOfClosed(aKC);
702 //=======================================================================
703 //function : DumpEdge
705 //=======================================================================
706 void GEOMAlgo_ShapeInfo::DumpEdge()const
708 Standard_Integer aNbV;
709 Standard_Real aX, aY, aZ;
710 GEOMAlgo_KindOfShape aKS;
711 GEOMAlgo_KindOfName aKN;
712 GEOMAlgo_KindOfBounds aKB;
713 GEOMAlgo_KindOfClosed aKC;
715 aNbV=NbSubShapes(TopAbs_VERTEX);
722 printf(" number of vertices: %d\n", aNbV);
723 DumpKindOfShape (aKS);
724 DumpKindOfName (aKN);
725 DumpKindOfBounds(aKB);
726 DumpKindOfClosed(aKC);
729 if (aKN==GEOMAlgo_KN_LINE) {
730 DumpLocation (myLocation);
731 DumpDirection(myDirection);
733 else if (aKN==GEOMAlgo_KN_SEGMENT) {
734 DumpLocation (myLocation);
735 DumpDirection(myDirection);
736 printf(" Length : %.3lf\n", myLength);
737 myPnt1.Coord(aX, aY, aZ);
738 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
739 myPnt2.Coord(aX, aY, aZ);
740 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
743 else if (aKN==GEOMAlgo_KN_CIRCLE) {
744 DumpLocation (myLocation);
745 DumpPosition (myPosition);
746 printf(" Radius1 : %.3lf\n", myRadius1);
748 else if (aKN==GEOMAlgo_KN_ARCCIRCLE) {
749 DumpLocation (myLocation);
750 DumpPosition (myPosition);
751 printf(" Radius1 : %.3lf\n", myRadius1);
752 myPnt1.Coord(aX, aY, aZ);
753 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
754 myPnt2.Coord(aX, aY, aZ);
755 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
757 else if (aKN==GEOMAlgo_KN_ELLIPSE) {
758 DumpLocation (myLocation);
759 DumpPosition (myPosition);
760 printf(" Radius1 : %.3lf\n", myRadius1);
761 printf(" Radius2 : %.3lf\n", myRadius2);
763 else if (aKN==GEOMAlgo_KN_ARCELLIPSE) {
764 DumpLocation (myLocation);
765 DumpPosition (myPosition);
766 printf(" Radius1 : %.3lf\n", myRadius1);
767 printf(" Radius2 : %.3lf\n", myRadius2);
768 myPnt1.Coord(aX, aY, aZ);
769 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
770 myPnt2.Coord(aX, aY, aZ);
771 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
775 //=======================================================================
776 //function : DumpVertex
778 //=======================================================================
779 void GEOMAlgo_ShapeInfo::DumpVertex()const
781 printf(" *VERTEX\n");
782 DumpLocation(myLocation);
784 //=======================================================================
785 //function : DumpLocation
787 //=======================================================================
788 void DumpLocation(const gp_Pnt& aP)
790 Standard_Real aX, aY, aZ;
792 aP.Coord(aX, aY, aZ);
793 printf(" Location : %.3lf %.3lf %.3lf \n", aX, aY, aZ);
795 //=======================================================================
796 //function : DumpDirection
798 //=======================================================================
799 void DumpDirection(const gp_Dir& aD)
801 Standard_Real aX, aY, aZ;
803 aD.Coord(aX, aY, aZ);
804 printf(" Direction: %.3lf %.3lf %.3lf \n", aX, aY, aZ);
806 //=======================================================================
807 //function : DumpPosition
809 //=======================================================================
810 void DumpPosition(const gp_Ax3& aAx3)
812 const gp_Dir& aDZ=aAx3.Axis().Direction();
813 const gp_Dir& aDX=aAx3.XDirection();
814 const gp_Dir& aDY=aAx3.YDirection();
815 printf(" Position:\n");
816 printf(" Axis: %.3lf %.3lf %.3lf \n", aDZ.X(), aDZ.Y(), aDZ.Z());
817 printf(" X : %.3lf %.3lf %.3lf \n", aDX.X(), aDX.Y(), aDX.Z());
818 printf(" Y : %.3lf %.3lf %.3lf \n", aDY.X(), aDY.Y(), aDY.Z());
820 //=======================================================================
821 //function : DumpKindOfBounds
823 //=======================================================================
824 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB)
833 i=(Standard_Integer)aKB;
834 printf(" KindOfBounds: %s\n", pStr[i]);
837 //=======================================================================
838 //function : DumpKindOfClosed
840 //=======================================================================
841 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC)
850 i=(Standard_Integer)aKC;
851 printf(" KindOfClosed: %s\n", pStr[i]);
854 //=======================================================================
855 //function : DumpKindOfShape
857 //=======================================================================
858 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS)
876 i=(Standard_Integer)aKS;
877 printf(" KindOfShape : %s\n", pStr[i]);
879 //=======================================================================
880 //function : DumpKindOfName
882 //=======================================================================
883 void DumpKindOfName(const GEOMAlgo_KindOfName aKS)
910 i=(Standard_Integer)aKS;
911 printf(" KindOfName : %s\n", pStr[i]);
913 //=======================================================================
914 //function : DumpKindOfDef
916 //=======================================================================
917 void DumpKindOfDef(const GEOMAlgo_KindOfDef aKD)
926 i=(Standard_Integer)aKD;
927 printf(" KindOfDef: %s\n", pStr[i]);