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