Salome HOME
3b38f8cc8763161bb3b1b8f2d76d8958e77bad8a
[modules/geom.git] / src / GEOMImpl / GEOMImpl_MarkerDriver.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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
29 #include <GEOM_Function.hxx>
30
31 #include <GEOMUtils.hxx>
32
33 #include <BRepBuilderAPI_MakeFace.hxx>
34 #include <BRep_Tool.hxx>
35
36 #include <TopAbs.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopExp.hxx>
42
43 #include <GC_MakePlane.hxx>
44 #include <Geom_Surface.hxx>
45
46 #include <Precision.hxx>
47 #include <gp_Ax3.hxx>
48 #include <gp_Pnt.hxx>
49 #include <gp_Pln.hxx>
50 #include <gp_Vec.hxx>
51
52 #include <Standard_ConstructionError.hxx>
53
54 //=======================================================================
55 //function : GetID
56 //purpose  :
57 //=======================================================================
58 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
59 {
60   static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
61   return aMarkerDriver;
62 }
63
64
65 //=======================================================================
66 //function : GEOMImpl_MarkerDriver
67 //purpose  :
68 //=======================================================================
69 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
70 {
71 }
72
73 //=======================================================================
74 //function : Execute
75 //purpose  :
76 //=======================================================================
77 Standard_Integer GEOMImpl_MarkerDriver::Execute(Handle(TFunction_Logbook)& log) const
78 {
79   if (Label().IsNull())  return 0;
80   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
81
82   GEOMImpl_IMarker aPI (aFunction);
83   Standard_Integer aType = aFunction->GetType();
84
85   TopoDS_Shape aShape;
86
87   if (aType == MARKER_CS) {
88     double OX, OY, OZ;
89     double XDX, XDY, XDZ;
90     double YDX, YDY, YDZ;
91     aPI.GetOrigin(OX, OY, OZ);
92     aPI.GetXDir(XDX, XDY, XDZ);
93     aPI.GetYDir(YDX, YDY, YDZ);
94
95     gp_Pnt aPO (OX, OY, OZ);
96     gp_Vec aVX (XDX, XDY, XDZ);
97     gp_Vec aVY (YDX, YDY, YDZ);
98     Standard_Real aTol = Precision::Confusion();
99     if (aVX.Magnitude() < aTol ||
100         aVY.Magnitude() < aTol ||
101         aVX.IsParallel(aVY, Precision::Angular())) {
102       Standard_ConstructionError::Raise("Degenerated or parallel directions given");
103     }
104
105     gp_Vec aN = aVX ^ aVY;
106     gp_Ax3 anA (aPO, aN, aVX);
107     gp_Pln aPln (anA);
108
109     double aTrimSize = 100.0;
110     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
111   } else if (aType == MARKER_SHAPE) {
112     Handle(GEOM_Function) aRefShape = aPI.GetShape();
113     TopoDS_Shape aSh = aRefShape->GetValue();
114     gp_Ax3 anAx3 = GEOMUtils::GetPosition(aSh);
115     gp_Pln aPln (anAx3);
116
117     double aTrimSize = 100.0;
118     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
119   } else if (aType == MARKER_PNT2VEC) {
120     Handle(GEOM_Function) aRefOrigin  = aPI.GetOrigin();
121     Handle(GEOM_Function) aRefXVec = aPI.GetXVec();
122     Handle(GEOM_Function) aRefYVec = aPI.GetYVec();
123     TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue();
124     TopoDS_Shape aShapeXVec = aRefXVec->GetValue();
125     TopoDS_Shape aShapeYVec = aRefYVec->GetValue();
126     if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0;
127     if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0;
128     if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0;
129
130     gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) );
131
132     gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) );
133     gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) );
134     gp_Vec aVX( aPX1, aPX2 );
135
136     gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) );
137     gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) );
138     gp_Vec aVY( aPY1, aPY2 );
139
140     if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution())
141         Standard_ConstructionError::Raise
142           ("Local CS creation aborted: vector of zero length is given");
143
144     if ( aVX.IsParallel(aVY, Precision::Angular()))
145       Standard_ConstructionError::Raise("Parallel Vectors given");
146     
147     gp_Vec aN = aVX ^ aVY;
148     gp_Ax3 anA (aPO, aN, aVX);
149     gp_Pln aPln (anA);
150     
151     double aTrimSize = 100.0;
152     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
153   } else {
154   }
155
156   if (aShape.IsNull()) return 0;
157
158   aFunction->SetValue(aShape);
159
160   log->SetTouched(Label());
161
162   return 1;
163 }
164
165 //================================================================================
166 /*!
167  * \brief Returns a name of creation operation and names and values of creation parameters
168  */
169 //================================================================================
170
171 bool GEOMImpl_MarkerDriver::
172 GetCreationInformation(std::string&             theOperationName,
173                        std::vector<GEOM_Param>& theParams)
174 {
175   if (Label().IsNull()) return 0;
176   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
177
178   GEOMImpl_IMarker aCI( function );
179   Standard_Integer aType = function->GetType();
180
181   theOperationName = "LOCAL_CS";
182
183   switch ( aType ) {
184   case MARKER_CS:
185   {
186     double OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ;
187     aCI.GetOrigin(OX, OY, OZ);
188     aCI.GetXDir(XDX, XDY, XDZ);
189     aCI.GetYDir(YDX, YDY, YDZ);
190     AddParam( theParams, "Coordinates of origin" ) << OX << ", " << OY << ", " << OZ;
191     AddParam( theParams, "X axis direction" ) << XDX << ", " << XDY << ", " << XDZ;
192     AddParam( theParams, "Y axis direction" ) << YDX << ", " << YDY << ", " << YDZ;
193     break;
194   }
195   case MARKER_SHAPE:
196     AddParam( theParams, "Object", aCI.GetShape() );
197     break;
198   case MARKER_PNT2VEC:
199     AddParam( theParams, "Point", aCI.GetOrigin() );
200     AddParam( theParams, "X axis direction", aCI.GetXVec() );
201     AddParam( theParams, "Y axis direction", aCI.GetYVec() );
202     break;
203   default:
204     return false;
205   }
206   
207   return true;
208 }
209
210 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_MarkerDriver,GEOM_BaseDriver)