]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_SketcherDriver.cxx
Salome HOME
0020555: EDF GEOM: MakeSketcher and localisation
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SketcherDriver.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_SketcherDriver.hxx>
25 #include <GEOMImpl_ISketcher.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <GEOMImpl_IMeasureOperations.hxx>
30
31 // OCCT Includes
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <BRep_Tool.hxx>
34 #include <Geom_Plane.hxx>
35 #include <TopoDS.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <gp_Pln.hxx>
38
39 #include <Sketcher_Profile.hxx>
40
41 #include <Standard_ConstructionError.hxx>
42
43 //=======================================================================
44 //function : GetID
45 //purpose  :
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
48 {
49   static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
50   return aSketcherDriver;
51 }
52
53
54 //=======================================================================
55 //function : GEOMImpl_SketcherDriver
56 //purpose  :
57 //=======================================================================
58 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
59 {
60 }
61
62 //=======================================================================
63 //function : Execute
64 //purpose  :
65 //=======================================================================
66 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
67 {
68   if (Label().IsNull()) return 0;
69   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70
71   GEOMImpl_ISketcher aCI (aFunction);
72   //Standard_Integer aType = aFunction->GetType();
73
74   // retrieve the command
75   TCollection_AsciiString aCommand = aCI.GetCommand();
76   if (aCommand.IsEmpty())
77     return 0;
78
79   TopoDS_Shape aShape;
80
81   // Set "C" numeric locale to save numbers correctly
82   std::string aCurLocale = setlocale(LC_NUMERIC, 0);
83   setlocale(LC_NUMERIC, "C");
84
85   // create sketcher
86   Sketcher_Profile aProfile (aCommand.ToCString());
87
88   // Return previous locale
89   setlocale(LC_NUMERIC, aCurLocale.data());
90
91   if (!aProfile.IsDone()) {
92     Standard_ConstructionError::Raise("Sketcher creation failed");
93   }
94
95   aShape = aProfile.GetShape();
96   if (aShape.IsNull())
97     return 0;
98
99   gp_Ax3 aWPlane;
100   if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
101   {
102     gp_Pnt aOrigin =
103       gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
104     gp_Dir aDirZ =
105       gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
106     gp_Dir aDirX =
107       gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
108     aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
109   }
110   else
111   {
112     Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
113     TopoDS_Shape aShape = aRefFace->GetValue();
114     //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
115     //  return 0;
116     //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
117     //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
118     //  return 0;
119     //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
120     //aWPlane = aGPlane->Pln().Position();
121     aWPlane = GEOMImpl_IMeasureOperations::GetPosition(aShape);
122   }
123   gp_Trsf aTrans;
124   aTrans.SetTransformation(aWPlane);
125   aTrans.Invert();
126   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
127   aShape = aTransformation.Shape();
128
129   if (aShape.IsNull())
130     return 0;
131
132   // set the function result
133   aFunction->SetValue(aShape);
134
135   log.SetTouched(Label());
136
137   return 1;
138 }
139
140
141 //=======================================================================
142 //function :  GEOMImpl_SketcherDriver_Type_
143 //purpose  :
144 //=======================================================================
145 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
146 {
147
148   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
149   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
150   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
151   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
152   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
153   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
154
155
156   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
157   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
158                                                          sizeof(GEOMImpl_SketcherDriver),
159                                                          1,
160                                                          (Standard_Address)_Ancestors,
161                                                          (Standard_Address)NULL);
162
163   return _aType;
164 }
165
166 //=======================================================================
167 //function : DownCast
168 //purpose  :
169 //=======================================================================
170 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
171 {
172   Handle(GEOMImpl_SketcherDriver) _anOtherObject;
173
174   if (!AnObject.IsNull()) {
175      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
176        _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
177      }
178   }
179
180   return _anOtherObject ;
181 }