1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_PrismDriver.hxx>
25 #include <GEOMImpl_IShapesOperations.hxx>
26 #include <GEOMImpl_IPrism.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepPrimAPI_MakePrism.hxx>
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
40 #include <Precision.hxx>
42 #include <gp_Trsf.hxx>
44 #include <Standard_ConstructionError.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
52 static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
57 //=======================================================================
58 //function : GEOMImpl_PrismDriver
60 //=======================================================================
61 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 GEOMImpl_IPrism aCI (aFunction);
75 Standard_Integer aType = aFunction->GetType();
79 if (aType == PRISM_BASE_VEC_H || aType == PRISM_BASE_VEC_H_2WAYS) {
80 Handle(GEOM_Function) aRefBase = aCI.GetBase();
81 Handle(GEOM_Function) aRefVector = aCI.GetVector();
82 TopoDS_Shape aShapeBase = aRefBase->GetValue();
83 TopoDS_Shape aShapeVec = aRefVector->GetValue();
84 if (aShapeVec.ShapeType() == TopAbs_EDGE) {
85 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
87 TopExp::Vertices(anE, V1, V2, Standard_True);
88 if (!V1.IsNull() && !V2.IsNull()) {
89 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
90 if (Abs(aCI.GetH()) < Precision::Confusion()) {
91 Standard_ConstructionError::Raise("Absolute value of prism height is too small");
93 if (aV.Magnitude() > Precision::Confusion()) {
95 if (aType == PRISM_BASE_VEC_H_2WAYS) {
97 aTrsf.SetTranslation( (-aV) * aCI.GetH() );
98 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
99 aShapeBase = aTransformation.Shape();
100 aCI.SetH( aCI.GetH()*2 );
102 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
106 } else if (aType == PRISM_BASE_TWO_PNT || aType == PRISM_BASE_TWO_PNT_2WAYS) {
107 Handle(GEOM_Function) aRefBase = aCI.GetBase();
108 Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
109 Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
110 TopoDS_Shape aShapeBase = aRefBase->GetValue();
111 TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
112 TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
113 if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
114 aShapePnt2.ShapeType() == TopAbs_VERTEX) {
115 TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
116 TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
117 if (!V1.IsNull() && !V2.IsNull()) {
118 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
119 if (aV.Magnitude() > gp::Resolution()) {
120 if (aType == PRISM_BASE_TWO_PNT_2WAYS)
123 aTrsf.SetTranslation(-aV);
124 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
125 aShapeBase = aTransformation.Shape();
128 aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
135 if (aShape.IsNull()) return 0;
137 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
138 aFunction->SetValue(aRes);
140 log.SetTouched(Label());
146 //=======================================================================
147 //function : GEOMImpl_PrismDriver_Type_
149 //=======================================================================
150 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
153 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
154 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
155 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
156 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
157 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
158 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
161 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
162 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
163 sizeof(GEOMImpl_PrismDriver),
165 (Standard_Address)_Ancestors,
166 (Standard_Address)NULL);
171 //=======================================================================
172 //function : DownCast
174 //=======================================================================
175 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
177 Handle(GEOMImpl_PrismDriver) _anOtherObject;
179 if (!AnObject.IsNull()) {
180 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
181 _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
185 return _anOtherObject ;