Salome HOME
Update copyright
[modules/geom.git] / src / GEOMImpl / GEOMImpl_MarkerDriver.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_MarkerDriver.hxx>
26 #include <GEOMImpl_IMarker.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
29 #include <GEOMImpl_IMeasureOperations.hxx>
30
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRep_Tool.hxx>
33
34 #include <TopAbs.hxx>
35 #include <TopoDS.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopExp.hxx>
40
41 #include <GC_MakePlane.hxx>
42 #include <Geom_Surface.hxx>
43
44 #include <Precision.hxx>
45 #include <gp_Ax3.hxx>
46 #include <gp_Pnt.hxx>
47 #include <gp_Pln.hxx>
48 #include <gp_Vec.hxx>
49
50 #include <Standard_ConstructionError.hxx>
51
52 //=======================================================================
53 //function : GetID
54 //purpose  :
55 //=======================================================================
56 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
57 {
58   static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
59   return aMarkerDriver;
60 }
61
62
63 //=======================================================================
64 //function : GEOMImpl_MarkerDriver
65 //purpose  :
66 //=======================================================================
67 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
68 {
69 }
70
71 //=======================================================================
72 //function : Execute
73 //purpose  :
74 //=======================================================================
75 Standard_Integer GEOMImpl_MarkerDriver::Execute(TFunction_Logbook& log) const
76 {
77   if (Label().IsNull())  return 0;
78   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
79
80   GEOMImpl_IMarker aPI (aFunction);
81   Standard_Integer aType = aFunction->GetType();
82
83   TopoDS_Shape aShape;
84
85   if (aType == MARKER_CS) {
86     double OX, OY, OZ;
87     double XDX, XDY, XDZ;
88     double YDX, YDY, YDZ;
89     aPI.GetOrigin(OX, OY, OZ);
90     aPI.GetXDir(XDX, XDY, XDZ);
91     aPI.GetYDir(YDX, YDY, YDZ);
92
93     gp_Pnt aPO (OX, OY, OZ);
94     gp_Vec aVX (XDX, XDY, XDZ);
95     gp_Vec aVY (YDX, YDY, YDZ);
96     Standard_Real aTol = Precision::Confusion();
97     if (aVX.Magnitude() < aTol ||
98         aVY.Magnitude() < aTol ||
99         aVX.IsParallel(aVY, Precision::Angular())) {
100       Standard_ConstructionError::Raise("Degenerated or parallel directions given");
101     }
102
103     gp_Vec aN = aVX ^ aVY;
104     gp_Ax3 anA (aPO, aN, aVX);
105     gp_Pln aPln (anA);
106
107     double aTrimSize = 100.0;
108     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
109   } else if (aType == MARKER_SHAPE) {
110     Handle(GEOM_Function) aRefShape = aPI.GetShape();
111     TopoDS_Shape aSh = aRefShape->GetValue();
112     gp_Ax3 anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aSh);
113     gp_Pln aPln (anAx3);
114
115     double aTrimSize = 100.0;
116     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
117   } else if (aType == MARKER_PNT2VEC) {
118     Handle(GEOM_Function) aRefOrigin  = aPI.GetOrigin();
119     Handle(GEOM_Function) aRefXVec = aPI.GetXVec();
120     Handle(GEOM_Function) aRefYVec = aPI.GetYVec();
121     TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue();
122     TopoDS_Shape aShapeXVec = aRefXVec->GetValue();
123     TopoDS_Shape aShapeYVec = aRefYVec->GetValue();
124     if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0;
125     if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0;
126     if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0;
127
128     gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) );
129
130     gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) );
131     gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) );
132     gp_Vec aVX( aPX1, aPX2 );
133
134     gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) );
135     gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) );
136     gp_Vec aVY( aPY1, aPY2 );
137
138     if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution())
139         Standard_ConstructionError::Raise
140           ("Local CS creation aborted: vector of zero length is given");
141
142     if ( aVX.IsParallel(aVY, Precision::Angular()))
143       Standard_ConstructionError::Raise("Parallel Vectors given");
144     
145     gp_Vec aN = aVX ^ aVY;
146     gp_Ax3 anA (aPO, aN, aVX);
147     gp_Pln aPln (anA);
148     
149     double aTrimSize = 100.0;
150     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
151   } else {
152   }
153
154   if (aShape.IsNull()) return 0;
155
156   aFunction->SetValue(aShape);
157
158   log.SetTouched(Label());
159
160   return 1;
161 }
162
163
164 //=======================================================================
165 //function :  GEOMImpl_MarkerDriver_Type_
166 //purpose  :
167 //=======================================================================
168 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MarkerDriver_Type_()
169 {
170
171   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
172   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
173   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
174   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
175   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
176   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
177
178
179   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
180   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MarkerDriver",
181                                                          sizeof(GEOMImpl_MarkerDriver),
182                                                          1,
183                                                          (Standard_Address)_Ancestors,
184                                                          (Standard_Address)NULL);
185
186   return _aType;
187 }
188
189 //=======================================================================
190 //function : DownCast
191 //purpose  :
192 //=======================================================================
193 const Handle(GEOMImpl_MarkerDriver) Handle(GEOMImpl_MarkerDriver)::DownCast
194        (const Handle(Standard_Transient)& AnObject)
195 {
196   Handle(GEOMImpl_MarkerDriver) _anOtherObject;
197
198   if (!AnObject.IsNull()) {
199      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MarkerDriver))) {
200        _anOtherObject = Handle(GEOMImpl_MarkerDriver)((Handle(GEOMImpl_MarkerDriver)&)AnObject);
201      }
202   }
203
204   return _anOtherObject ;
205 }