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