Salome HOME
Copyrights update
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PointDriver.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/
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_PointDriver.hxx>
24 #include <GEOMImpl_IPoint.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRep_Tool.hxx>
29 #include <BRepBuilderAPI_MakeVertex.hxx>
30
31 #include <TopAbs.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Vertex.hxx>
36
37 #include <Geom_Curve.hxx>
38 #include <gp_Pnt.hxx>
39
40 //=======================================================================
41 //function : GetID
42 //purpose  :
43 //=======================================================================
44 const Standard_GUID& GEOMImpl_PointDriver::GetID()
45 {
46   static Standard_GUID aPointDriver("FF1BBB02-5D14-4df2-980B-3A668264EA16");
47   return aPointDriver;
48 }
49
50
51 //=======================================================================
52 //function : GEOMImpl_PointDriver
53 //purpose  :
54 //=======================================================================
55 GEOMImpl_PointDriver::GEOMImpl_PointDriver()
56 {
57 }
58
59 //=======================================================================
60 //function : Execute
61 //purpose  :
62 //=======================================================================
63 Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
64 {
65   if (Label().IsNull())  return 0;
66   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67
68   GEOMImpl_IPoint aPI (aFunction);
69   Standard_Integer aType = aFunction->GetType();
70
71   gp_Pnt aPnt;
72
73   if (aType == POINT_XYZ) {
74     aPnt = gp_Pnt(aPI.GetX(), aPI.GetY(), aPI.GetZ());
75
76   } else if (aType == POINT_XYZ_REF) {
77
78     Handle(GEOM_Function) aRefPoint = aPI.GetRef();
79     TopoDS_Shape aRefShape = aRefPoint->GetValue();
80     if (aRefShape.ShapeType() != TopAbs_VERTEX) {
81       Standard_TypeMismatch::Raise
82         ("Point creation aborted : referenced shape is not a vertex");
83     }
84     gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aRefShape));
85     aPnt = gp_Pnt(P.X() + aPI.GetX(), P.Y() + aPI.GetY(), P.Z() + aPI.GetZ());
86
87   } else if (aType == POINT_CURVE_PAR) {
88
89     Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
90     TopoDS_Shape aRefShape = aRefCurve->GetValue();
91     if (aRefShape.ShapeType() != TopAbs_EDGE) {
92       Standard_TypeMismatch::Raise
93         ("Point On Curve creation aborted : curve shape is not an edge");
94     }
95     Standard_Real aFP, aLP, aP;
96     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aRefShape), aFP, aLP);
97     aP = aFP + (aLP - aFP) * aPI.GetParameter();
98     aPnt = aCurve->Value(aP);
99
100   } else {
101     return 0;
102   }
103
104   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
105   TopoDS_Shape aShape = mkVertex.Shape();
106   aShape.Infinite(Standard_True);
107   aFunction->SetValue(aShape);
108
109   log.SetTouched(Label());
110
111   return 1;
112 }
113
114
115 //=======================================================================
116 //function :  GEOMImpl_PointDriver_Type_
117 //purpose  :
118 //=======================================================================
119 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PointDriver_Type_()
120 {
121
122   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
123   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
124   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
125   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
126   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
127   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
128
129
130   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
131   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PointDriver",
132                                                          sizeof(GEOMImpl_PointDriver),
133                                                          1,
134                                                          (Standard_Address)_Ancestors,
135                                                          (Standard_Address)NULL);
136
137   return _aType;
138 }
139
140 //=======================================================================
141 //function : DownCast
142 //purpose  :
143 //=======================================================================
144
145 const Handle(GEOMImpl_PointDriver) Handle(GEOMImpl_PointDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
146 {
147   Handle(GEOMImpl_PointDriver) _anOtherObject;
148
149   if (!AnObject.IsNull()) {
150      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PointDriver))) {
151        _anOtherObject = Handle(GEOMImpl_PointDriver)((Handle(GEOMImpl_PointDriver)&)AnObject);
152      }
153   }
154
155   return _anOtherObject ;
156 }
157
158