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_PositionDriver.hxx>
24 #include <GEOMImpl_IPosition.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <GEOMImpl_IMeasureOperations.hxx>
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
39 #include <Geom_Plane.hxx>
40 #include <GProp_GProps.hxx>
41 #include <BRepGProp.hxx>
43 #include <Precision.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
52 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
53 return aPositionDriver;
57 //=======================================================================
58 //function : GEOMImpl_PositionDriver
60 //=======================================================================
61 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 GEOMImpl_IPosition aCI (aFunction);
75 Standard_Integer aType = aFunction->GetType();
79 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
80 Handle(GEOM_Function) aRefShape = aCI.GetShape();
81 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
82 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
84 TopoDS_Shape aShapeBase = aRefShape->GetValue();
85 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
86 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
88 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
89 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
93 gp_Ax3 aStartAx3, aDestAx3;
96 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
99 aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
101 // Set transformation
102 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
104 // Perform transformation
105 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
106 aShape = aBRepTrsf.Shape();
108 else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
109 aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
110 Handle(GEOM_Function) aRefShape = aCI.GetShape();
111 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
113 TopoDS_Shape aShapeBase = aRefShape->GetValue();
114 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
116 if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
117 aShapeEndLCS.ShapeType() != TopAbs_FACE)
121 gp_Ax3 aStartAx3, aDestAx3;
124 aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
126 // Set transformation
127 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
129 // Perform transformation
130 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
131 aShape = aBRepTrsf.Shape();
136 if (aShape.IsNull()) return 0;
138 aFunction->SetValue(aShape);
140 log.SetTouched(Label());
146 //=======================================================================
147 //function : GEOMImpl_PositionDriver_Type_
149 //=======================================================================
150 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_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_PositionDriver",
163 sizeof(GEOMImpl_PositionDriver),
165 (Standard_Address)_Ancestors,
166 (Standard_Address)NULL);
171 //=======================================================================
172 //function : DownCast
174 //=======================================================================
175 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
177 Handle(GEOMImpl_PositionDriver) _anOtherObject;
179 if (!AnObject.IsNull()) {
180 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
181 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
185 return _anOtherObject ;