1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_PrismDriver.hxx>
26 #include <GEOMImpl_IShapesOperations.hxx>
27 #include <GEOMImpl_IPrism.hxx>
28 #include <GEOMImpl_Types.hxx>
29 #include <GEOM_Function.hxx>
31 #include <BRepPrimAPI_MakePrism.hxx>
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <BRep_Tool.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Vertex.hxx>
41 #include <Precision.hxx>
43 #include <gp_Trsf.hxx>
45 #include <Standard_ConstructionError.hxx>
47 //=======================================================================
50 //=======================================================================
51 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
53 static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
58 //=======================================================================
59 //function : GEOMImpl_PrismDriver
61 //=======================================================================
62 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 GEOMImpl_IPrism aCI (aFunction);
76 Standard_Integer aType = aFunction->GetType();
80 if (aType == PRISM_BASE_VEC_H || aType == PRISM_BASE_VEC_H_2WAYS) {
81 Handle(GEOM_Function) aRefBase = aCI.GetBase();
82 Handle(GEOM_Function) aRefVector = aCI.GetVector();
83 TopoDS_Shape aShapeBase = aRefBase->GetValue();
84 TopoDS_Shape aShapeVec = aRefVector->GetValue();
85 if (aShapeVec.ShapeType() == TopAbs_EDGE) {
86 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
88 TopExp::Vertices(anE, V1, V2, Standard_True);
89 if (!V1.IsNull() && !V2.IsNull()) {
90 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
91 if (Abs(aCI.GetH()) < Precision::Confusion()) {
92 Standard_ConstructionError::Raise("Absolute value of prism height is too small");
94 if (aV.Magnitude() > Precision::Confusion()) {
96 if (aType == PRISM_BASE_VEC_H_2WAYS) {
98 aTrsf.SetTranslation( (-aV) * aCI.GetH() );
99 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
100 aShapeBase = aTransformation.Shape();
101 aCI.SetH( aCI.GetH()*2 );
103 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
107 } else if (aType == PRISM_BASE_TWO_PNT || aType == PRISM_BASE_TWO_PNT_2WAYS) {
108 Handle(GEOM_Function) aRefBase = aCI.GetBase();
109 Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
110 Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
111 TopoDS_Shape aShapeBase = aRefBase->GetValue();
112 TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
113 TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
114 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
115 aShapePnt2.ShapeType() == TopAbs_VERTEX) {
116 TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
117 TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
118 if (!V1.IsNull() && !V2.IsNull()) {
119 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
120 if (aV.Magnitude() > gp::Resolution()) {
121 if (aType == PRISM_BASE_TWO_PNT_2WAYS)
124 aTrsf.SetTranslation(-aV);
125 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
126 aShapeBase = aTransformation.Shape();
129 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
133 } else if (aType == PRISM_BASE_DXDYDZ || aType == PRISM_BASE_DXDYDZ_2WAYS) {
134 Handle(GEOM_Function) aRefBase = aCI.GetBase();
135 TopoDS_Shape aShapeBase = aRefBase->GetValue();
136 gp_Vec aV (aCI.GetDX(), aCI.GetDY(), aCI.GetDZ());
137 if (aV.Magnitude() > gp::Resolution()) {
138 if (aType == PRISM_BASE_DXDYDZ_2WAYS)
141 aTrsf.SetTranslation(-aV);
142 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
143 aShapeBase = aTransformation.Shape();
146 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
150 if (aShape.IsNull()) return 0;
152 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
153 aFunction->SetValue(aRes);
155 log.SetTouched(Label());
161 //=======================================================================
162 //function : GEOMImpl_PrismDriver_Type_
164 //=======================================================================
165 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
168 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
169 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
170 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
171 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
172 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
173 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
176 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
177 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
178 sizeof(GEOMImpl_PrismDriver),
180 (Standard_Address)_Ancestors,
181 (Standard_Address)NULL);
186 //=======================================================================
187 //function : DownCast
189 //=======================================================================
190 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
192 Handle(GEOMImpl_PrismDriver) _anOtherObject;
194 if (!AnObject.IsNull()) {
195 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
196 _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
200 return _anOtherObject ;