Salome HOME
- Patch for recent Debian distrib:
[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
29 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <BRep_Tool.hxx>
31
32 #include <TopAbs.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopExp.hxx>
38
39 #include <GC_MakePlane.hxx>
40 #include <Geom_Surface.hxx>
41
42 #include <Precision.hxx>
43 #include <gp_Ax3.hxx>
44 #include <gp_Pnt.hxx>
45 #include <gp_Pln.hxx>
46 #include <gp_Vec.hxx>
47
48 #include <Standard_ConstructionError.hxx>
49
50 //=======================================================================
51 //function : GetID
52 //purpose  :
53 //=======================================================================
54 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
55 {
56   static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
57   return aMarkerDriver;
58 }
59
60
61 //=======================================================================
62 //function : GEOMImpl_MarkerDriver
63 //purpose  :
64 //=======================================================================
65 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
66 {
67 }
68
69 //=======================================================================
70 //function : Execute
71 //purpose  :
72 //=======================================================================
73 Standard_Integer GEOMImpl_MarkerDriver::Execute(TFunction_Logbook& log) const
74 {
75   if (Label().IsNull())  return 0;
76   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
77
78   GEOMImpl_IMarker aPI (aFunction);
79   Standard_Integer aType = aFunction->GetType();
80
81   TopoDS_Shape aShape;
82
83   if (aType == MARKER_CS) {
84     double OX, OY, OZ;
85     double XDX, XDY, XDZ;
86     double YDX, YDY, YDZ;
87     aPI.GetOrigin(OX, OY, OZ);
88     aPI.GetXDir(XDX, XDY, XDZ);
89     aPI.GetYDir(YDX, YDY, YDZ);
90
91     gp_Pnt aPO (OX, OY, OZ);
92     gp_Vec aVX (XDX, XDY, XDZ);
93     gp_Vec aVY (YDX, YDY, YDZ);
94     Standard_Real aTol = Precision::Confusion();
95     if (aVX.Magnitude() < aTol ||
96         aVY.Magnitude() < aTol ||
97         aVX.IsParallel(aVY, Precision::Angular())) {
98       Standard_ConstructionError::Raise("Degenerated or parallel directions given");
99     }
100
101     gp_Vec aN = aVX ^ aVY;
102     gp_Ax3 anA (aPO, aN, aVX);
103     gp_Pln aPln (anA);
104
105     double aTrimSize = 100.0;
106     aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
107   } else {
108   }
109
110   if (aShape.IsNull()) return 0;
111
112   aFunction->SetValue(aShape);
113
114   log.SetTouched(Label());
115
116   return 1;
117 }
118
119
120 //=======================================================================
121 //function :  GEOMImpl_MarkerDriver_Type_
122 //purpose  :
123 //=======================================================================
124 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MarkerDriver_Type_()
125 {
126
127   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
128   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
129   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
130   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
131   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
132   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
133
134
135   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
136   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MarkerDriver",
137                                                          sizeof(GEOMImpl_MarkerDriver),
138                                                          1,
139                                                          (Standard_Address)_Ancestors,
140                                                          (Standard_Address)NULL);
141
142   return _aType;
143 }
144
145 //=======================================================================
146 //function : DownCast
147 //purpose  :
148 //=======================================================================
149 const Handle(GEOMImpl_MarkerDriver) Handle(GEOMImpl_MarkerDriver)::DownCast
150        (const Handle(Standard_Transient)& AnObject)
151 {
152   Handle(GEOMImpl_MarkerDriver) _anOtherObject;
153
154   if (!AnObject.IsNull()) {
155      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MarkerDriver))) {
156        _anOtherObject = Handle(GEOMImpl_MarkerDriver)((Handle(GEOMImpl_MarkerDriver)&)AnObject);
157      }
158   }
159
160   return _anOtherObject ;
161 }