Salome HOME
0021684: EDF 2221 : Display the arguments and the name of the operations
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SketcherDriver.cxx
1 // Copyright (C) 2007-2013  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 #include <GEOMUtils.hxx>
29 #include <Sketcher_Profile.hxx>
30
31 #include <Basics_Utils.hxx>
32
33 // OCCT Includes
34 #include <BRepBuilderAPI_Transform.hxx>
35 #include <BRep_Tool.hxx>
36 #include <Geom_Plane.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <gp_Pln.hxx>
40 #include <Standard_ConstructionError.hxx>
41
42 //=======================================================================
43 //function : GetID
44 //purpose  :
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
47 {
48   static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
49   return aSketcherDriver;
50 }
51
52
53 //=======================================================================
54 //function : GEOMImpl_SketcherDriver
55 //purpose  :
56 //=======================================================================
57 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
58 {
59 }
60
61 //=======================================================================
62 //function : Execute
63 //purpose  :
64 //=======================================================================
65 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
66 {
67   if (Label().IsNull()) return 0;
68   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
69
70   GEOMImpl_ISketcher aCI (aFunction);
71   //Standard_Integer aType = aFunction->GetType();
72
73   // retrieve the command
74   TCollection_AsciiString aCommand = aCI.GetCommand();
75   if (aCommand.IsEmpty())
76     return 0;
77
78   // Set "C" numeric locale to save numbers correctly
79   Kernel_Utils::Localizer loc;
80
81   // create sketcher
82   Sketcher_Profile aProfile( aCommand.ToCString() );
83   bool isDone = false;
84   TopoDS_Shape aShape = aProfile.GetShape( &isDone );
85
86   if ( !isDone ) {
87     Standard_ConstructionError::Raise("Sketcher creation failed");
88   }
89
90   if (aShape.IsNull())
91     return 0;
92
93   gp_Ax3 aWPlane;
94   if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
95   {
96     gp_Pnt aOrigin =
97       gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
98     gp_Dir aDirZ =
99       gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
100     gp_Dir aDirX =
101       gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
102     aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
103   }
104   else
105   {
106     Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
107     TopoDS_Shape aShape = aRefFace->GetValue();
108     //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
109     //  return 0;
110     //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
111     //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
112     //  return 0;
113     //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
114     //aWPlane = aGPlane->Pln().Position();
115     aWPlane = GEOMUtils::GetPosition(aShape);
116   }
117   gp_Trsf aTrans;
118   aTrans.SetTransformation(aWPlane);
119   aTrans.Invert();
120   BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
121   aShape = aTransformation.Shape();
122
123   if (aShape.IsNull())
124     return 0;
125
126   // set the function result
127   aFunction->SetValue(aShape);
128
129   log.SetTouched(Label());
130
131   return 1;
132 }
133
134 //================================================================================
135 /*!
136  * \brief Returns a name of creation operation and names and values of creation parameters
137  */
138 //================================================================================
139
140 bool GEOMImpl_SketcherDriver::
141 GetCreationInformation(std::string&             theOperationName,
142                        std::vector<GEOM_Param>& theParams)
143 {
144   if (Label().IsNull()) return 0;
145   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
146
147   GEOMImpl_ISketcher aCI( function );
148   Standard_Integer aType = function->GetType();
149
150   theOperationName = "SKETCH";
151
152   switch ( aType ) {
153   case SKETCHER_NINE_DOUBLS:
154     AddParam( theParams, "Command", aCI.GetCommand() );
155     AddParam( theParams, "Origin")
156       << aCI.GetWorkingPlane(1) << " "
157       << aCI.GetWorkingPlane(2) << " "
158       << aCI.GetWorkingPlane(3);
159     AddParam( theParams, "OZ")
160       << aCI.GetWorkingPlane(4) << " "
161       << aCI.GetWorkingPlane(5) << " "
162       << aCI.GetWorkingPlane(6);
163     AddParam( theParams, "OX")
164       << aCI.GetWorkingPlane(7) << " "
165       << aCI.GetWorkingPlane(8) << " "
166       << aCI.GetWorkingPlane(9);
167     break;
168   case SKETCHER_PLANE:
169     AddParam( theParams, "Command", aCI.GetCommand() );
170     AddParam( theParams, "Working plane", aCI.GetWorkingPlane(), "XOY" );
171     break;
172   default:
173     return false;
174   }
175
176   return true;
177 }
178
179 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SketcherDriver,GEOM_BaseDriver);
180 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SketcherDriver,GEOM_BaseDriver);