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