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_PositionDriver.hxx>
25 #include <GEOMImpl_IPosition.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <GEOMImpl_IMeasureOperations.hxx>
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <ShHealOper_EdgeDivide.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepTools.hxx>
36 #include <BRepFill_LocationLaw.hxx>
37 #include <BRepFill_Edge3DLaw.hxx>
38 #include <BRepFill_SectionPlacement.hxx>
39 #include <BRepTools_WireExplorer.hxx>
40 #include <BRepBuilderAPI_MakeWire.hxx>
41 #include <BRepBuilderAPI_MakeVertex.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Wire.hxx>
49 #include <TopExp_Explorer.hxx>
51 #include <Geom_Plane.hxx>
52 #include <Geom_Curve.hxx>
53 #include <GProp_GProps.hxx>
54 #include <BRepGProp.hxx>
55 #include <ShapeAnalysis_Edge.hxx>
56 #include <GeomAdaptor_Curve.hxx>
57 #include <BRepGProp.hxx>
58 #include <ShapeFix_Wire.hxx>
60 #include <GeomFill_TrihedronLaw.hxx>
61 #include <GeomFill_CurveAndTrihedron.hxx>
62 #include <GeomFill_CorrectedFrenet.hxx>
64 #include <Precision.hxx>
69 //=======================================================================
72 //=======================================================================
73 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
75 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
76 return aPositionDriver;
80 //=======================================================================
81 //function : GEOMImpl_PositionDriver
83 //=======================================================================
84 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
88 //=======================================================================
91 //=======================================================================
92 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
94 if (Label().IsNull()) return 0;
95 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
97 GEOMImpl_IPosition aCI (aFunction);
98 Standard_Integer aType = aFunction->GetType();
102 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
103 Handle(GEOM_Function) aRefShape = aCI.GetShape();
104 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
105 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
107 TopoDS_Shape aShapeBase = aRefShape->GetValue();
108 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
109 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
111 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
112 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
116 gp_Ax3 aStartAx3, aDestAx3;
119 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
122 aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
124 // Set transformation
125 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
127 // Perform transformation
128 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
129 aShape = aBRepTrsf.Shape();
131 else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
132 aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
133 Handle(GEOM_Function) aRefShape = aCI.GetShape();
134 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
136 TopoDS_Shape aShapeBase = aRefShape->GetValue();
137 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
139 if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
140 aShapeEndLCS.ShapeType() != TopAbs_FACE)
144 gp_Ax3 aStartAx3, aDestAx3;
147 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
149 // Set transformation
150 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
152 // Perform transformation
153 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
154 aShape = aBRepTrsf.Shape();
156 else if (aType == POSITION_ALONG_PATH) {
157 Handle(GEOM_Function) aRefShape = aCI.GetShape();
158 Handle(GEOM_Function) aPathShape = aCI.GetPath();
159 Standard_Real aParameter = aCI.GetDistance();
160 bool aReversed = aCI.GetReverse();
162 aParameter = 1 - aParameter;
164 TopoDS_Shape aShapeBase = aRefShape->GetValue();
165 TopoDS_Shape aPath = aPathShape->GetValue();
168 if (aShapeBase.IsNull() || aPath.IsNull())
171 if ( aPath.ShapeType() == TopAbs_EDGE ) {
172 TopoDS_Edge anEdge = TopoDS::Edge(aPath);
173 aWire = BRepBuilderAPI_MakeWire(anEdge);
175 else if ( aPath.ShapeType() == TopAbs_WIRE)
176 aWire = TopoDS::Wire(aPath);
180 Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet();
181 Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw );
182 Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw);
184 aLocation->TransformInCompatibleLaw( 0.01 );
186 //Calculate a Parameter
187 Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge
188 Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge
189 aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2);
191 if ( aLocation->NbLaw() > 1)
192 aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1);
193 else if ( aLocation->NbLaw() == 1 )
194 aFirstParam1 = aFirstParam2;
198 Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter );
200 TopoDS_Shape CopyShape = aShapeBase;
201 BRepFill_SectionPlacement Place( aLocation, aShapeBase );
202 TopLoc_Location Loc2(Place.Transformation()), Loc1;
203 Loc1 = CopyShape.Location();
204 CopyShape.Location(Loc2.Multiplied(Loc1));
206 aLocation->D0( aParam, CopyShape );
212 if (aShape.IsNull()) return 0;
214 aFunction->SetValue(aShape);
216 log.SetTouched(Label());
222 //=======================================================================
223 //function : GEOMImpl_PositionDriver_Type_
225 //=======================================================================
226 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
229 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
230 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
231 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
232 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
233 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
234 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
237 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
238 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
239 sizeof(GEOMImpl_PositionDriver),
241 (Standard_Address)_Ancestors,
242 (Standard_Address)NULL);
247 //=======================================================================
248 //function : DownCast
250 //=======================================================================
251 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
253 Handle(GEOMImpl_PositionDriver) _anOtherObject;
255 if (!AnObject.IsNull()) {
256 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
257 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
261 return _anOtherObject ;