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 <BRep_Tool.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
40 #include <Geom_Plane.hxx>
41 #include <GProp_GProps.hxx>
42 #include <BRepGProp.hxx>
44 #include <Precision.hxx>
47 //=======================================================================
50 //=======================================================================
51 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
53 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
54 return aPositionDriver;
58 //=======================================================================
59 //function : GEOMImpl_PositionDriver
61 //=======================================================================
62 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 GEOMImpl_IPosition aCI (aFunction);
76 Standard_Integer aType = aFunction->GetType();
80 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
81 Handle(GEOM_Function) aRefShape = aCI.GetShape();
82 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
83 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
85 TopoDS_Shape aShapeBase = aRefShape->GetValue();
86 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
87 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
89 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
90 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
94 gp_Ax3 aStartAx3, aDestAx3;
97 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
100 aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
102 // Set transformation
103 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
105 // Perform transformation
106 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
107 aShape = aBRepTrsf.Shape();
109 else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
110 aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
111 Handle(GEOM_Function) aRefShape = aCI.GetShape();
112 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
114 TopoDS_Shape aShapeBase = aRefShape->GetValue();
115 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
117 if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
118 aShapeEndLCS.ShapeType() != TopAbs_FACE)
122 gp_Ax3 aStartAx3, aDestAx3;
125 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
127 // Set transformation
128 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
130 // Perform transformation
131 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
132 aShape = aBRepTrsf.Shape();
137 if (aShape.IsNull()) return 0;
139 aFunction->SetValue(aShape);
141 log.SetTouched(Label());
147 //=======================================================================
148 //function : GEOMImpl_PositionDriver_Type_
150 //=======================================================================
151 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
154 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
155 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
156 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
157 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
158 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
159 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
162 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
163 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
164 sizeof(GEOMImpl_PositionDriver),
166 (Standard_Address)_Ancestors,
167 (Standard_Address)NULL);
172 //=======================================================================
173 //function : DownCast
175 //=======================================================================
176 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
178 Handle(GEOMImpl_PositionDriver) _anOtherObject;
180 if (!AnObject.IsNull()) {
181 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
182 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
186 return _anOtherObject ;