1 // Copyright (C) 2007-2010 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
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_PrismDriver.hxx>
27 #include <GEOMImpl_IShapesOperations.hxx>
28 #include <GEOMImpl_IPrism.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOM_Function.hxx>
32 #include <BRepPrimAPI_MakePrism.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <BRep_Tool.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
42 #include <Precision.hxx>
44 #include <gp_Trsf.hxx>
46 #include <Standard_ConstructionError.hxx>
48 //=======================================================================
51 //=======================================================================
52 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
54 static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
59 //=======================================================================
60 //function : GEOMImpl_PrismDriver
62 //=======================================================================
63 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver()
67 //=======================================================================
70 //=======================================================================
71 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
73 if (Label().IsNull()) return 0;
74 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
76 GEOMImpl_IPrism aCI (aFunction);
77 Standard_Integer aType = aFunction->GetType();
81 if (aType == PRISM_BASE_VEC_H || aType == PRISM_BASE_VEC_H_2WAYS) {
82 Handle(GEOM_Function) aRefBase = aCI.GetBase();
83 Handle(GEOM_Function) aRefVector = aCI.GetVector();
84 TopoDS_Shape aShapeBase = aRefBase->GetValue();
85 TopoDS_Shape aShapeVec = aRefVector->GetValue();
86 if (aShapeVec.ShapeType() == TopAbs_EDGE) {
87 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
89 TopExp::Vertices(anE, V1, V2, Standard_True);
90 if (!V1.IsNull() && !V2.IsNull()) {
91 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
92 if (Abs(aCI.GetH()) < Precision::Confusion()) {
93 Standard_ConstructionError::Raise("Absolute value of prism height is too small");
95 if (aV.Magnitude() > Precision::Confusion()) {
97 if (aType == PRISM_BASE_VEC_H_2WAYS) {
99 aTrsf.SetTranslation( (-aV) * aCI.GetH() );
100 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
101 aShapeBase = aTransformation.Shape();
102 aCI.SetH( aCI.GetH()*2 );
104 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
108 } else if (aType == PRISM_BASE_TWO_PNT || aType == PRISM_BASE_TWO_PNT_2WAYS) {
109 Handle(GEOM_Function) aRefBase = aCI.GetBase();
110 Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
111 Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
112 TopoDS_Shape aShapeBase = aRefBase->GetValue();
113 TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
114 TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
115 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
116 aShapePnt2.ShapeType() == TopAbs_VERTEX) {
117 TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
118 TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
119 if (!V1.IsNull() && !V2.IsNull()) {
120 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
121 if (aV.Magnitude() > gp::Resolution()) {
122 if (aType == PRISM_BASE_TWO_PNT_2WAYS)
125 aTrsf.SetTranslation(-aV);
126 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
127 aShapeBase = aTransformation.Shape();
130 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
134 } else if (aType == PRISM_BASE_DXDYDZ || aType == PRISM_BASE_DXDYDZ_2WAYS) {
135 Handle(GEOM_Function) aRefBase = aCI.GetBase();
136 TopoDS_Shape aShapeBase = aRefBase->GetValue();
137 gp_Vec aV (aCI.GetDX(), aCI.GetDY(), aCI.GetDZ());
138 if (aV.Magnitude() > gp::Resolution()) {
139 if (aType == PRISM_BASE_DXDYDZ_2WAYS)
142 aTrsf.SetTranslation(-aV);
143 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
144 aShapeBase = aTransformation.Shape();
147 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
151 if (aShape.IsNull()) return 0;
153 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
154 aFunction->SetValue(aRes);
156 log.SetTouched(Label());
162 //=======================================================================
163 //function : GEOMImpl_PrismDriver_Type_
165 //=======================================================================
166 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
169 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
170 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
171 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
172 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
173 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
174 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
177 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
178 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
179 sizeof(GEOMImpl_PrismDriver),
181 (Standard_Address)_Ancestors,
182 (Standard_Address)NULL);
187 //=======================================================================
188 //function : DownCast
190 //=======================================================================
191 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
193 Handle(GEOMImpl_PrismDriver) _anOtherObject;
195 if (!AnObject.IsNull()) {
196 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
197 _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
201 return _anOtherObject ;