Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SketcherDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_SketcherDriver.hxx"
4 #include "GEOMImpl_ISketcher.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <TopoDS_Shape.hxx>
9 #include <gp_Dir.hxx>
10 #include <gp_Ax3.hxx>
11 #include <BRepBuilderAPI_Transform.hxx>
12
13 #include <Sketcher_Profile.hxx>
14
15 #include <Standard_ConstructionError.hxx>
16
17 //=======================================================================
18 //function : GetID
19 //purpose  :
20 //=======================================================================
21 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
22 {
23   static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
24   return aSketcherDriver;
25 }
26
27
28 //=======================================================================
29 //function : GEOMImpl_SketcherDriver
30 //purpose  :
31 //=======================================================================
32 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
33 {
34 }
35
36 //=======================================================================
37 //function : Execute
38 //purpose  :
39 //=======================================================================
40 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
41 {
42   if (Label().IsNull()) return 0;
43   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
44
45   GEOMImpl_ISketcher aCI (aFunction);
46   //Standard_Integer aType = aFunction->GetType();
47
48   // retrieve the command
49   TCollection_AsciiString aCommand = aCI.GetCommand();
50   if (aCommand.IsEmpty())
51     return 0;
52
53   TopoDS_Shape aShape;
54
55   // create sketcher
56   Sketcher_Profile aProfile (aCommand.ToCString());
57
58   if (!aProfile.IsDone()) {
59     Standard_ConstructionError::Raise("Sketcher creation failed");
60   }
61
62   aShape = aProfile.GetShape();
63   if (aShape.IsNull())
64     return 0;
65
66   gp_Trsf aTrans;
67   gp_Pnt aOrigin = gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
68   gp_Dir aDirZ = gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
69   gp_Dir aDirX = gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
70   gp_Ax3 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
71
72   aTrans.SetTransformation(aWPlane);
73   aTrans.Invert();
74   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
75   aShape = aTransformation.Shape();
76
77   if (aShape.IsNull())
78     return 0;
79
80   // set the function result
81   aFunction->SetValue(aShape);
82
83   log.SetTouched(Label());
84
85   return 1;
86 }
87
88
89 //=======================================================================
90 //function :  GEOMImpl_SketcherDriver_Type_
91 //purpose  :
92 //=======================================================================
93 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
94 {
95
96   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
97   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
98   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
99   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
100   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
101   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
102
103
104   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
105   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
106                                                          sizeof(GEOMImpl_SketcherDriver),
107                                                          1,
108                                                          (Standard_Address)_Ancestors,
109                                                          (Standard_Address)NULL);
110
111   return _aType;
112 }
113
114 //=======================================================================
115 //function : DownCast
116 //purpose  :
117 //=======================================================================
118 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
119 {
120   Handle(GEOMImpl_SketcherDriver) _anOtherObject;
121
122   if (!AnObject.IsNull()) {
123      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
124        _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
125      }
126   }
127
128   return _anOtherObject ;
129 }