Salome HOME
NPAL15298: KindOfShape(). A tool by PKV.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PositionDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
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.
8 //
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 //#include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_PositionDriver.hxx>
24 #include <GEOMImpl_IPosition.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <GEOMImpl_IMeasureOperations.hxx>
29
30 // OCCT Includes
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include <BRep_Tool.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopAbs.hxx>
37 #include <TopExp.hxx>
38 #include <gp_Pln.hxx>
39 #include <Geom_Plane.hxx>
40 #include <GProp_GProps.hxx>
41 #include <BRepGProp.hxx>
42
43 #include <Precision.hxx>
44 #include <gp_Pnt.hxx>
45
46 //=======================================================================
47 //function : GetID
48 //purpose  :
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
51 {
52   static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
53   return aPositionDriver;
54 }
55
56
57 //=======================================================================
58 //function : GEOMImpl_PositionDriver
59 //purpose  :
60 //=======================================================================
61 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
62 {
63 }
64
65 //=======================================================================
66 //function : Execute
67 //purpose  :
68 //=======================================================================
69 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
70 {
71   if (Label().IsNull()) return 0;
72   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73
74   GEOMImpl_IPosition aCI (aFunction);
75   Standard_Integer aType = aFunction->GetType();
76
77   TopoDS_Shape aShape;
78
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();
83
84     TopoDS_Shape aShapeBase = aRefShape->GetValue();
85     TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
86     TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
87
88     if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
89         aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
90       return 0;
91
92     gp_Trsf aTrsf;
93     gp_Ax3 aStartAx3, aDestAx3;
94
95     // End LCS
96     aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
97
98     // Start LCS
99     aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);
100
101     // Set transformation
102     aTrsf.SetDisplacement(aStartAx3, aDestAx3);
103
104     // Perform transformation
105     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
106     aShape = aBRepTrsf.Shape();
107   }
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();
112
113     TopoDS_Shape aShapeBase = aRefShape->GetValue();
114     TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
115
116     if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
117         aShapeEndLCS.ShapeType() != TopAbs_FACE)
118       return 0;
119
120     gp_Trsf aTrsf;
121     gp_Ax3 aStartAx3, aDestAx3;
122
123     // End LCS
124     aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);
125
126     // Set transformation
127     aTrsf.SetDisplacement(aStartAx3, aDestAx3);
128
129     // Perform transformation
130     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
131     aShape = aBRepTrsf.Shape();
132   }
133   else
134     return 0;
135
136   if (aShape.IsNull()) return 0;
137
138   aFunction->SetValue(aShape);
139
140   log.SetTouched(Label());
141
142   return 1;
143 }
144
145
146 //=======================================================================
147 //function :  GEOMImpl_PositionDriver_Type_
148 //purpose  :
149 //=======================================================================
150 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
151 {
152
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);
159
160
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),
164                                                          1,
165                                                          (Standard_Address)_Ancestors,
166                                                          (Standard_Address)NULL);
167
168   return _aType;
169 }
170
171 //=======================================================================
172 //function : DownCast
173 //purpose  :
174 //=======================================================================
175 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
176 {
177   Handle(GEOMImpl_PositionDriver) _anOtherObject;
178
179   if (!AnObject.IsNull()) {
180      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
181        _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
182      }
183   }
184
185   return _anOtherObject ;
186 }