1 // Copyright (C) 2007-2014 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 DumpPosition(const gp_Ax3& aAx3);
35 void DumpLocation(const gp_Pnt& aP);
37 void DumpDirection(const gp_Dir& aD);
38 //=======================================================================
41 //=======================================================================
42 GEOMAlgo_ShapeInfo::GEOMAlgo_ShapeInfo()
46 //=======================================================================
49 //=======================================================================
50 GEOMAlgo_ShapeInfo::~GEOMAlgo_ShapeInfo()
53 //=======================================================================
56 //=======================================================================
57 void GEOMAlgo_ShapeInfo::Reset()
64 for (i=0; i<myNbTypes; ++i) {
68 myKindOfShape=GEOMAlgo_KS_UNKNOWN;
69 myKindOfBounds=GEOMAlgo_KB_UNKNOWN;
70 myKindOfClosed=GEOMAlgo_KC_UNKNOWN;
71 myKindOfName=GEOMAlgo_KN_UNKNOWN;
73 myLocation.SetCoord(99., 99., 99.);
74 myDirection.SetCoord(1.,0.,0.);
82 //=======================================================================
85 //=======================================================================
86 void GEOMAlgo_ShapeInfo::SetType(const TopAbs_ShapeEnum aType)
90 //=======================================================================
93 //=======================================================================
94 TopAbs_ShapeEnum GEOMAlgo_ShapeInfo::Type() const
98 //=======================================================================
99 //function : SetNbSubShapes
101 //=======================================================================
102 void GEOMAlgo_ShapeInfo::SetNbSubShapes(const TopAbs_ShapeEnum aType,
103 const Standard_Integer aNb)
107 iN=TypeToInteger(aType);
108 if (iN>=0 && iN<myNbTypes) {
109 myNbSubShapes[iN]=aNb;
112 //=======================================================================
113 //function : NbSubShapes
115 //=======================================================================
116 Standard_Integer GEOMAlgo_ShapeInfo::NbSubShapes(const TopAbs_ShapeEnum aType) const
120 iN=TypeToInteger(aType);
121 if (iN>=0 && iN<myNbTypes) {
122 return myNbSubShapes[iN];
126 //=======================================================================
127 //function : SetKindOfShape
129 //=======================================================================
130 void GEOMAlgo_ShapeInfo::SetKindOfShape(const GEOMAlgo_KindOfShape aT)
134 //=======================================================================
135 //function : KindOfShape
137 //=======================================================================
138 GEOMAlgo_KindOfShape GEOMAlgo_ShapeInfo::KindOfShape() const
140 return myKindOfShape;
142 //=======================================================================
143 //function : SetKindOfName
145 //=======================================================================
146 void GEOMAlgo_ShapeInfo::SetKindOfName(const GEOMAlgo_KindOfName aT)
150 //=======================================================================
151 //function : KindOfName
153 //=======================================================================
154 GEOMAlgo_KindOfName GEOMAlgo_ShapeInfo::KindOfName() const
158 //=======================================================================
159 //function : SetKindOfBounds
161 //=======================================================================
162 void GEOMAlgo_ShapeInfo::SetKindOfBounds(const GEOMAlgo_KindOfBounds aT)
166 //=======================================================================
167 //function : KindOfBounds
169 //=======================================================================
170 GEOMAlgo_KindOfBounds GEOMAlgo_ShapeInfo::KindOfBounds() const
172 return myKindOfBounds;
174 //=======================================================================
175 //function : SetKindOfClosed
177 //=======================================================================
178 void GEOMAlgo_ShapeInfo::SetKindOfClosed(const GEOMAlgo_KindOfClosed aT)
182 //=======================================================================
183 //function : KindOfClosed
185 //=======================================================================
186 GEOMAlgo_KindOfClosed GEOMAlgo_ShapeInfo::KindOfClosed() const
188 return myKindOfClosed;
190 //=======================================================================
191 //function : SetLocation
193 //=======================================================================
194 void GEOMAlgo_ShapeInfo::SetLocation(const gp_Pnt& aP)
198 //=======================================================================
199 //function : Location
201 //=======================================================================
202 const gp_Pnt& GEOMAlgo_ShapeInfo::Location() const
206 //=======================================================================
207 //function : SetDirection
209 //=======================================================================
210 void GEOMAlgo_ShapeInfo::SetDirection(const gp_Dir& aD)
214 //=======================================================================
215 //function : Direction
217 //=======================================================================
218 const gp_Dir& GEOMAlgo_ShapeInfo::Direction() const
222 //=======================================================================
223 //function : SetPosition
225 //=======================================================================
226 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax2& aAx2)
231 //=======================================================================
232 //function : SetPosition
234 //=======================================================================
235 void GEOMAlgo_ShapeInfo::SetPosition(const gp_Ax3& aAx3)
239 //=======================================================================
240 //function : Position
242 //=======================================================================
243 const gp_Ax3& GEOMAlgo_ShapeInfo::Position() const
248 //=======================================================================
251 //=======================================================================
252 void GEOMAlgo_ShapeInfo::SetPnt1(const gp_Pnt& aP)
256 //=======================================================================
259 //=======================================================================
260 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt1() const
264 //=======================================================================
267 //=======================================================================
268 void GEOMAlgo_ShapeInfo::SetPnt2(const gp_Pnt& aP)
272 //=======================================================================
275 //=======================================================================
276 const gp_Pnt& GEOMAlgo_ShapeInfo::Pnt2() const
280 //=======================================================================
281 //function : SetRadius1
283 //=======================================================================
284 void GEOMAlgo_ShapeInfo::SetRadius1(const Standard_Real aR)
288 //=======================================================================
291 //=======================================================================
292 Standard_Real GEOMAlgo_ShapeInfo::Radius1() const
296 //=======================================================================
297 //function : SetRadius2
299 //=======================================================================
300 void GEOMAlgo_ShapeInfo::SetRadius2(const Standard_Real aR)
304 //=======================================================================
307 //=======================================================================
308 Standard_Real GEOMAlgo_ShapeInfo::Radius2() const
312 //=======================================================================
313 //function : SetLength
315 //=======================================================================
316 void GEOMAlgo_ShapeInfo::SetLength(const Standard_Real aL)
320 //=======================================================================
323 //=======================================================================
324 Standard_Real GEOMAlgo_ShapeInfo::Length() const
328 //=======================================================================
329 //function : SetWidth
331 //=======================================================================
332 void GEOMAlgo_ShapeInfo::SetWidth(const Standard_Real aW)
336 //=======================================================================
339 //=======================================================================
340 Standard_Real GEOMAlgo_ShapeInfo::Width() const
344 //=======================================================================
345 //function : SetHeight
347 //=======================================================================
348 void GEOMAlgo_ShapeInfo::SetHeight(const Standard_Real aH)
352 //=======================================================================
355 //=======================================================================
356 Standard_Real GEOMAlgo_ShapeInfo::Height() const
360 //=======================================================================
361 //function : TypeToInteger
363 //=======================================================================
364 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType)
368 iN=(Standard_Integer)aType;
371 //=======================================================================
374 //=======================================================================
375 void GEOMAlgo_ShapeInfo::Dump()const
403 case TopAbs_COMPSOLID:
407 case TopAbs_COMPOUND:
412 printf(" * not implememted yet\n");
416 //=======================================================================
417 //function : DumpCompound
419 //=======================================================================
420 void GEOMAlgo_ShapeInfo::DumpCompound()const
422 Standard_Integer aNbV, aNbE, aNbF, aNbS, aNbC, aNbP;
423 GEOMAlgo_KindOfShape aKS;
424 GEOMAlgo_KindOfName aKN;
425 GEOMAlgo_KindOfBounds aKB;
426 GEOMAlgo_KindOfClosed aKC;
428 aNbV=NbSubShapes(TopAbs_VERTEX);
429 aNbE=NbSubShapes(TopAbs_EDGE);
430 aNbF=NbSubShapes(TopAbs_FACE);
431 aNbS=NbSubShapes(TopAbs_SOLID);
432 aNbC=NbSubShapes(TopAbs_COMPSOLID);
433 aNbP=NbSubShapes(TopAbs_COMPOUND);
439 printf(" *COMPOUND\n");
440 printf(" number of vertices : %d\n", aNbV);
441 printf(" number of edges : %d\n", aNbE);
442 printf(" number of faces : %d\n", aNbF);
443 printf(" number of solids : %d\n", aNbS);
444 printf(" number of compsolids : %d\n", aNbC);
445 printf(" number of compounds : %d\n", aNbP);
446 DumpKindOfShape (aKS);
447 DumpKindOfName (aKN);
448 DumpKindOfBounds(aKB);
449 DumpKindOfClosed(aKC);
451 //=======================================================================
452 //function : DumpCompSolid
454 //=======================================================================
455 void GEOMAlgo_ShapeInfo::DumpCompSolid()const
457 Standard_Integer aNbV, aNbE, aNbF, aNbS;
458 GEOMAlgo_KindOfShape aKS;
459 GEOMAlgo_KindOfName aKN;
460 GEOMAlgo_KindOfBounds aKB;
461 GEOMAlgo_KindOfClosed aKC;
463 aNbV=NbSubShapes(TopAbs_VERTEX);
464 aNbE=NbSubShapes(TopAbs_EDGE);
465 aNbF=NbSubShapes(TopAbs_FACE);
466 aNbS=NbSubShapes(TopAbs_SOLID);
472 printf(" *COMPSOLID\n");
473 printf(" number of vertices: %d\n", aNbV);
474 printf(" number of edges : %d\n", aNbE);
475 printf(" number of faces : %d\n", aNbF);
476 printf(" number of solids : %d\n", aNbS);
477 DumpKindOfShape (aKS);
478 DumpKindOfName (aKN);
479 DumpKindOfBounds(aKB);
480 DumpKindOfClosed(aKC);
483 //=======================================================================
484 //function : DumpSolid
486 //=======================================================================
487 void GEOMAlgo_ShapeInfo::DumpSolid()const
489 Standard_Integer aNbV, aNbE, aNbF;
490 GEOMAlgo_KindOfShape aKS;
491 GEOMAlgo_KindOfName aKN;
492 GEOMAlgo_KindOfBounds aKB;
493 GEOMAlgo_KindOfClosed aKC;
495 aNbV=NbSubShapes(TopAbs_VERTEX);
496 aNbE=NbSubShapes(TopAbs_EDGE);
497 aNbF=NbSubShapes(TopAbs_FACE);
504 printf(" number of vertices: %d\n", aNbV);
505 printf(" number of edges : %d\n", aNbE);
506 printf(" number of faces : %d\n", aNbF);
507 DumpKindOfShape (aKS);
508 DumpKindOfName (aKN);
509 DumpKindOfBounds(aKB);
510 DumpKindOfClosed(aKC);
512 if (aKN==GEOMAlgo_KN_SPHERE) {
513 DumpLocation (myLocation);
514 DumpPosition (myPosition);
515 printf(" Radius1 : %.3lf\n", myRadius1);
517 if (aKN==GEOMAlgo_KN_CYLINDER) {
518 DumpLocation (myLocation);
519 DumpPosition (myPosition);
520 printf(" Radius1 : %.3lf\n", myRadius1);
521 printf(" Height : %.3lf\n", myHeight);
523 else if (aKN==GEOMAlgo_KN_CONE) {
524 DumpLocation (myLocation);
525 DumpPosition (myPosition);
526 printf(" Radius1 : %.3lf\n", myRadius1);
527 printf(" Radius2 : %.3lf\n", myRadius2);
528 printf(" Height : %.3lf\n", myHeight);
530 else if (aKN==GEOMAlgo_KN_TORUS) {
531 DumpLocation (myLocation);
532 DumpPosition (myPosition);
533 printf(" Radius1 : %.3lf\n", myRadius1);
534 printf(" Radius2 : %.3lf\n", myRadius2);
536 else if (aKN==GEOMAlgo_KN_POLYHEDRON) {
537 DumpLocation (myLocation);
538 DumpPosition (myPosition);
540 else if (aKN==GEOMAlgo_KN_BOX) {
541 DumpLocation (myLocation);
542 DumpPosition (myPosition);
543 printf(" Length : %.3lf\n", myLength);
544 printf(" Width : %.3lf\n", myWidth);
545 printf(" Height : %.3lf\n", myHeight);
549 //=======================================================================
550 //function : DumpFace
552 //=======================================================================
553 void GEOMAlgo_ShapeInfo::DumpFace()const
555 Standard_Integer aNbV, aNbE;
556 GEOMAlgo_KindOfShape aKS;
557 GEOMAlgo_KindOfName aKN;
558 GEOMAlgo_KindOfBounds aKB;
559 GEOMAlgo_KindOfClosed aKC;
561 aNbV=NbSubShapes(TopAbs_VERTEX);
562 aNbE=NbSubShapes(TopAbs_EDGE);
569 printf(" number of vertices: %d\n", aNbV);
570 printf(" number of edges : %d\n", aNbE);
571 DumpKindOfShape (aKS);
572 DumpKindOfName (aKN);
573 DumpKindOfBounds(aKB);
574 DumpKindOfClosed(aKC);
577 if (aKN==GEOMAlgo_KN_PLANE) {
578 DumpLocation (myLocation);
579 DumpPosition (myPosition);
581 else if (aKN==GEOMAlgo_KN_DISKCIRCLE) {
582 DumpLocation (myLocation);
583 DumpPosition (myPosition);
584 printf(" Radius1 : %.3lf\n", myRadius1);
586 else if (aKN==GEOMAlgo_KN_DISKELLIPSE) {
587 DumpLocation (myLocation);
588 DumpPosition (myPosition);
589 printf(" Radius1 : %.3lf\n", myRadius1);
590 printf(" Radius2 : %.3lf\n", myRadius2);
592 else if (aKN==GEOMAlgo_KN_RECTANGLE) {
593 DumpLocation (myLocation);
594 DumpPosition (myPosition);
595 printf(" Length : %.3lf\n", myLength);
596 printf(" Width : %.3lf\n", myWidth);
598 else if (aKN==GEOMAlgo_KN_TRIANGLE ||
599 aKN==GEOMAlgo_KN_QUADRANGLE||
600 aKN==GEOMAlgo_KN_POLYGON) {
601 DumpLocation (myLocation);
602 DumpPosition (myPosition);
606 else if (aKN==GEOMAlgo_KN_SPHERE) {
607 DumpLocation (myLocation);
608 DumpPosition (myPosition);
609 printf(" Radius1 : %.3lf", myRadius1);
613 else if (aKN==GEOMAlgo_KN_CYLINDER) {
614 DumpLocation (myLocation);
615 DumpPosition (myPosition);
616 printf(" Radius1 : %.3lf\n", myRadius1);
617 printf(" Height : %.3lf\n", myHeight);
621 else if (aKN==GEOMAlgo_KN_CONE) {
622 DumpLocation (myLocation);
623 DumpPosition (myPosition);
624 printf(" Radius1 : %.3lf\n", myRadius1);
625 printf(" Radius2 : %.3lf\n", myRadius2);
626 printf(" Height : %.3lf\n", myHeight);
630 else if (aKN==GEOMAlgo_KN_TORUS) {
631 DumpLocation (myLocation);
632 DumpPosition (myPosition);
633 printf(" Radius1 : %.3lf\n", myRadius1);
634 printf(" Radius2 : %.3lf\n", myRadius2);
640 //=======================================================================
641 //function : DumpShell
643 //=======================================================================
644 void GEOMAlgo_ShapeInfo::DumpShell()const
646 Standard_Integer aNbV, aNbE, aNbF;
647 GEOMAlgo_KindOfClosed aKC;
651 aNbV=NbSubShapes(TopAbs_VERTEX);
652 aNbE=NbSubShapes(TopAbs_EDGE);
653 aNbF=NbSubShapes(TopAbs_FACE);
654 printf(" number of vertices: %d\n", aNbV);
655 printf(" number of edges : %d\n", aNbE);
656 printf(" number of faces : %d\n", aNbF);
658 DumpKindOfClosed(aKC);
661 //=======================================================================
662 //function : DumpWire
664 //=======================================================================
665 void GEOMAlgo_ShapeInfo::DumpWire()const
667 Standard_Integer aNbV, aNbE;
668 GEOMAlgo_KindOfClosed aKC;
672 aNbV=NbSubShapes(TopAbs_VERTEX);
673 aNbE=NbSubShapes(TopAbs_EDGE);
674 printf(" number of vertices: %d\n", aNbV);
675 printf(" number of edges : %d\n", aNbE);
678 DumpKindOfClosed(aKC);
681 //=======================================================================
682 //function : DumpEdge
684 //=======================================================================
685 void GEOMAlgo_ShapeInfo::DumpEdge()const
687 Standard_Integer aNbV;
688 Standard_Real aX, aY, aZ;
689 GEOMAlgo_KindOfShape aKS;
690 GEOMAlgo_KindOfName aKN;
691 GEOMAlgo_KindOfBounds aKB;
692 GEOMAlgo_KindOfClosed aKC;
694 aNbV=NbSubShapes(TopAbs_VERTEX);
701 printf(" number of vertices: %d\n", aNbV);
702 DumpKindOfShape (aKS);
703 DumpKindOfName (aKN);
704 DumpKindOfBounds(aKB);
705 DumpKindOfClosed(aKC);
708 if (aKN==GEOMAlgo_KN_LINE) {
709 DumpLocation (myLocation);
710 DumpDirection(myDirection);
712 else if (aKN==GEOMAlgo_KN_SEGMENT) {
713 DumpLocation (myLocation);
714 DumpDirection(myDirection);
715 printf(" Length : %.3lf\n", myLength);
716 myPnt1.Coord(aX, aY, aZ);
717 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
718 myPnt2.Coord(aX, aY, aZ);
719 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
722 else if (aKN==GEOMAlgo_KN_CIRCLE) {
723 DumpLocation (myLocation);
724 DumpPosition (myPosition);
725 printf(" Radius1 : %.3lf\n", myRadius1);
727 else if (aKN==GEOMAlgo_KN_ARCCIRCLE) {
728 DumpLocation (myLocation);
729 DumpPosition (myPosition);
730 printf(" Radius1 : %.3lf\n", myRadius1);
731 myPnt1.Coord(aX, aY, aZ);
732 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
733 myPnt2.Coord(aX, aY, aZ);
734 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
736 else if (aKN==GEOMAlgo_KN_ELLIPSE) {
737 DumpLocation (myLocation);
738 DumpPosition (myPosition);
739 printf(" Radius1 : %.3lf\n", myRadius1);
740 printf(" Radius2 : %.3lf\n", myRadius2);
742 else if (aKN==GEOMAlgo_KN_ARCELLIPSE) {
743 DumpLocation (myLocation);
744 DumpPosition (myPosition);
745 printf(" Radius1 : %.3lf\n", myRadius1);
746 printf(" Radius2 : %.3lf\n", myRadius2);
747 myPnt1.Coord(aX, aY, aZ);
748 printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
749 myPnt2.Coord(aX, aY, aZ);
750 printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ);
754 //=======================================================================
755 //function : DumpVertex
757 //=======================================================================
758 void GEOMAlgo_ShapeInfo::DumpVertex()const
760 printf(" *VERTEX\n");
761 DumpLocation(myLocation);
763 //=======================================================================
764 //function : DumpLocation
766 //=======================================================================
767 void DumpLocation(const gp_Pnt& aP)
769 Standard_Real aX, aY, aZ;
771 aP.Coord(aX, aY, aZ);
772 printf(" Location : %.3lf %.3lf %.3lf \n", aX, aY, aZ);
774 //=======================================================================
775 //function : DumpDirection
777 //=======================================================================
778 void DumpDirection(const gp_Dir& aD)
780 Standard_Real aX, aY, aZ;
782 aD.Coord(aX, aY, aZ);
783 printf(" Direction: %.3lf %.3lf %.3lf \n", aX, aY, aZ);
785 //=======================================================================
786 //function : DumpPosition
788 //=======================================================================
789 void DumpPosition(const gp_Ax3& aAx3)
791 const gp_Dir& aDZ=aAx3.Axis().Direction();
792 const gp_Dir& aDX=aAx3.XDirection();
793 const gp_Dir& aDY=aAx3.YDirection();
794 printf(" Position:\n");
795 printf(" Axis: %.3lf %.3lf %.3lf \n", aDZ.X(), aDZ.Y(), aDZ.Z());
796 printf(" X : %.3lf %.3lf %.3lf \n", aDX.X(), aDX.Y(), aDX.Z());
797 printf(" Y : %.3lf %.3lf %.3lf \n", aDY.X(), aDY.Y(), aDY.Z());
799 //=======================================================================
800 //function : DumpKindOfBounds
802 //=======================================================================
803 void DumpKindOfBounds(const GEOMAlgo_KindOfBounds aKB)
812 i=(Standard_Integer)aKB;
813 printf(" KindOfBounds: %s\n", pStr[i]);
816 //=======================================================================
817 //function : DumpKindOfClosed
819 //=======================================================================
820 void DumpKindOfClosed(const GEOMAlgo_KindOfClosed aKC)
829 i=(Standard_Integer)aKC;
830 printf(" KindOfClosed: %s\n", pStr[i]);
833 //=======================================================================
834 //function : DumpKindOfShape
836 //=======================================================================
837 void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS)
855 i=(Standard_Integer)aKS;
856 printf(" KindOfShape : %s\n", pStr[i]);
858 //=======================================================================
859 //function : DumpKindOfName
861 //=======================================================================
862 void DumpKindOfName(const GEOMAlgo_KindOfName aKS)
888 i=(Standard_Integer)aKS;
889 printf(" KindOfName : %s\n", pStr[i]);