1 // Created on: 2020-01-31
2 // Created by: Svetlana SHUTINA
3 // Copyright (c) 2020 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepPreviewAPI_MakeBox.hxx>
18 #include <BRep_Builder.hxx>
19 #include <BRepBuilderAPI_MakeEdge.hxx>
20 #include <BRepBuilderAPI_MakeFace.hxx>
21 #include <BRepBuilderAPI_MakeVertex.hxx>
22 #include <BRepBuilderAPI_MakeWire.hxx>
24 #include <TopoDS_Compound.hxx>
26 //=======================================================================
29 //=======================================================================
30 void BRepPreviewAPI_MakeBox::Build()
32 gp_Pnt anLocation = myWedge.Axes().Location();
34 gp_Pnt aFirstPoint (anLocation.X(), anLocation.Y(), anLocation.Z());
35 gp_Pnt aSecondPoint (anLocation.X() + myWedge.GetXMax(), anLocation.Y() + myWedge.GetYMax(), anLocation.Z() + myWedge.GetZMax());
37 Standard_Boolean aThinOnX = Abs (aFirstPoint.X() - aSecondPoint.X()) < Precision::Confusion();
38 Standard_Boolean aThinOnY = Abs (aFirstPoint.Y() - aSecondPoint.Y()) < Precision::Confusion();
39 Standard_Boolean aThinOnZ = Abs (aFirstPoint.Z() - aSecondPoint.Z()) < Precision::Confusion();
41 Standard_Integer aPreviewType = (int)aThinOnX + (int)aThinOnY + (int)aThinOnZ;
43 if (aPreviewType == 3) // thin box in all directions is a point
45 makeVertex (aFirstPoint);
47 else if (aPreviewType == 2) // thin box in two directions is a point
49 makeEdge (aFirstPoint, aSecondPoint);
51 // thin box in only one direction is a rectangular face
52 else if (aPreviewType == 1)
54 gp_Pnt aPnt1, aPnt2, aPnt3, aPnt4;
57 aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
58 aPnt2 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
59 aPnt3 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aSecondPoint.Z());
60 aPnt4 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
64 aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
65 aPnt2 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
66 aPnt3 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
67 aPnt4 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aSecondPoint.Z());
71 aPnt1 = gp_Pnt (aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
72 aPnt2 = gp_Pnt (aSecondPoint.X(), aFirstPoint.Y(), aFirstPoint.Z());
73 aPnt3 = gp_Pnt (aSecondPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
74 aPnt4 = gp_Pnt (aFirstPoint.X(), aSecondPoint.Y(), aFirstPoint.Z());
77 makeRectangle (aPnt1, aPnt2, aPnt3, aPnt4);
80 if (!myShape.IsNull())
86 // box is a valid shape
90 //=======================================================================
91 //function : makeVertex
93 //=======================================================================
94 void BRepPreviewAPI_MakeBox::makeVertex (const gp_Pnt& thePoint)
96 myShape = BRepBuilderAPI_MakeVertex (thePoint);
99 //=======================================================================
100 //function : makeEdge
102 //=======================================================================
103 void BRepPreviewAPI_MakeBox::makeEdge (const gp_Pnt& thePoint1, const gp_Pnt& thePoint2)
105 myShape = BRepBuilderAPI_MakeEdge (thePoint1, thePoint2);
108 //=======================================================================
109 //function : makeRectangle
111 //=======================================================================
112 void BRepPreviewAPI_MakeBox::makeRectangle (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2,
113 const gp_Pnt& thePnt3, const gp_Pnt& thePnt4)
115 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge (thePnt1, thePnt2);
116 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge (thePnt2, thePnt3);
117 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge (thePnt3, thePnt4);
118 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge (thePnt4, thePnt1);
120 BRepBuilderAPI_MakeWire aWire (anEdge1, anEdge2, anEdge3, anEdge4);
121 BRepBuilderAPI_MakeFace aFace (aWire);
123 myShape = aFace.Shape();