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_PositionDriver.hxx>
26 #include <GEOMImpl_IPosition.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <GEOMImpl_IMeasureOperations.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <ShHealOper_EdgeDivide.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRepTools.hxx>
37 #include <BRepFill_LocationLaw.hxx>
38 #include <BRepFill_Edge3DLaw.hxx>
39 #include <BRepFill_SectionPlacement.hxx>
40 #include <BRepTools_WireExplorer.hxx>
41 #include <BRepBuilderAPI_MakeWire.hxx>
42 #include <BRepBuilderAPI_MakeVertex.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Wire.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <Geom_Plane.hxx>
53 #include <Geom_Curve.hxx>
54 #include <GProp_GProps.hxx>
55 #include <BRepGProp.hxx>
56 #include <ShapeAnalysis_Edge.hxx>
57 #include <GeomAdaptor_Curve.hxx>
58 #include <BRepGProp.hxx>
59 #include <ShapeFix_Wire.hxx>
61 #include <GeomFill_TrihedronLaw.hxx>
62 #include <GeomFill_CurveAndTrihedron.hxx>
63 #include <GeomFill_CorrectedFrenet.hxx>
65 #include <Precision.hxx>
70 //=======================================================================
73 //=======================================================================
74 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
76 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
77 return aPositionDriver;
81 //=======================================================================
82 //function : GEOMImpl_PositionDriver
84 //=======================================================================
85 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
89 //=======================================================================
92 //=======================================================================
93 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
95 if (Label().IsNull()) return 0;
96 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
98 GEOMImpl_IPosition aCI (aFunction);
99 Standard_Integer aType = aFunction->GetType();
103 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
104 Handle(GEOM_Function) aRefShape = aCI.GetShape();
105 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
106 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
108 TopoDS_Shape aShapeBase = aRefShape->GetValue();
109 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
110 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
112 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
113 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
117 gp_Ax3 aStartAx3, aDestAx3;
120 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
123 aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
125 // Set transformation
126 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
128 // Perform transformation
129 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
130 aShape = aBRepTrsf.Shape();
132 else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
133 aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
134 Handle(GEOM_Function) aRefShape = aCI.GetShape();
135 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
137 TopoDS_Shape aShapeBase = aRefShape->GetValue();
138 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
140 if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
141 aShapeEndLCS.ShapeType() != TopAbs_FACE)
145 gp_Ax3 aStartAx3, aDestAx3;
148 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
150 // Set transformation
151 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
153 // Perform transformation
154 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
155 aShape = aBRepTrsf.Shape();
157 else if (aType == POSITION_ALONG_PATH) {
158 Handle(GEOM_Function) aRefShape = aCI.GetShape();
159 Handle(GEOM_Function) aPathShape = aCI.GetPath();
160 Standard_Real aParameter = aCI.GetDistance();
161 bool aReversed = aCI.GetReverse();
163 aParameter = 1 - aParameter;
165 TopoDS_Shape aShapeBase = aRefShape->GetValue();
166 TopoDS_Shape aPath = aPathShape->GetValue();
169 if (aShapeBase.IsNull() || aPath.IsNull())
172 if ( aPath.ShapeType() == TopAbs_EDGE ) {
173 TopoDS_Edge anEdge = TopoDS::Edge(aPath);
174 aWire = BRepBuilderAPI_MakeWire(anEdge);
176 else if ( aPath.ShapeType() == TopAbs_WIRE)
177 aWire = TopoDS::Wire(aPath);
181 Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet();
182 Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw );
183 Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw);
185 aLocation->TransformInCompatibleLaw( 0.01 );
187 //Calculate a Parameter
188 Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge
189 Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge
190 aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2);
192 if ( aLocation->NbLaw() > 1)
193 aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1);
194 else if ( aLocation->NbLaw() == 1 )
195 aFirstParam1 = aFirstParam2;
199 Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter );
201 TopoDS_Shape CopyShape = aShapeBase;
202 BRepFill_SectionPlacement Place( aLocation, aShapeBase );
203 TopLoc_Location Loc2(Place.Transformation()), Loc1;
204 Loc1 = CopyShape.Location();
205 CopyShape.Location(Loc2.Multiplied(Loc1));
207 aLocation->D0( aParam, CopyShape );
213 if (aShape.IsNull()) return 0;
215 aFunction->SetValue(aShape);
217 log.SetTouched(Label());
223 //=======================================================================
224 //function : GEOMImpl_PositionDriver_Type_
226 //=======================================================================
227 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
230 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
231 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
232 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
233 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
234 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
235 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
238 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
239 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
240 sizeof(GEOMImpl_PositionDriver),
242 (Standard_Address)_Ancestors,
243 (Standard_Address)NULL);
248 //=======================================================================
249 //function : DownCast
251 //=======================================================================
252 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
254 Handle(GEOMImpl_PositionDriver) _anOtherObject;
256 if (!AnObject.IsNull()) {
257 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
258 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
262 return _anOtherObject ;