1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_SketcherDriver.hxx>
26 #include <GEOMImpl_ISketcher.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
29 #include <GEOMUtils.hxx>
30 #include <Sketcher_Profile.hxx>
32 #include <Basics_Utils.hxx>
35 #include <BRepBuilderAPI_Transform.hxx>
36 #include <BRep_Tool.hxx>
37 #include <Geom_Plane.hxx>
39 #include <TopoDS_Shape.hxx>
41 #include <Standard_ConstructionError.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
49 static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
50 return aSketcherDriver;
54 //=======================================================================
55 //function : GEOMImpl_SketcherDriver
57 //=======================================================================
58 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_SketcherDriver::Execute(LOGBOOK& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_ISketcher aCI (aFunction);
72 //Standard_Integer aType = aFunction->GetType();
74 // retrieve the command
75 TCollection_AsciiString aCommand = aCI.GetCommand();
76 if (aCommand.IsEmpty())
79 // Set "C" numeric locale to save numbers correctly
80 Kernel_Utils::Localizer loc;
83 Sketcher_Profile aProfile( aCommand.ToCString() );
85 TopoDS_Shape aShape = aProfile.GetShape( &isDone );
88 Standard_ConstructionError::Raise("Sketcher creation failed");
95 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
98 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
100 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
102 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
103 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
107 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
108 TopoDS_Shape aShape = aRefFace->GetValue();
109 //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
111 //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
112 //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
114 //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
115 //aWPlane = aGPlane->Pln().Position();
116 aWPlane = GEOMUtils::GetPosition(aShape);
119 aTrans.SetTransformation(aWPlane);
121 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
122 aShape = aTransformation.Shape();
127 // set the function result
128 aFunction->SetValue(aShape);
130 #if OCC_VERSION_MAJOR < 7
131 log.SetTouched(Label());
133 log->SetTouched(Label());
139 //================================================================================
141 * \brief Returns a name of creation operation and names and values of creation parameters
143 //================================================================================
145 bool GEOMImpl_SketcherDriver::
146 GetCreationInformation(std::string& theOperationName,
147 std::vector<GEOM_Param>& theParams)
149 if (Label().IsNull()) return 0;
150 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
152 GEOMImpl_ISketcher aCI( function );
153 Standard_Integer aType = function->GetType();
155 theOperationName = "SKETCH";
158 case SKETCHER_NINE_DOUBLS:
159 AddParam( theParams, "Command", aCI.GetCommand() );
160 AddParam( theParams, "Origin")
161 << aCI.GetWorkingPlane(1) << " "
162 << aCI.GetWorkingPlane(2) << " "
163 << aCI.GetWorkingPlane(3);
164 AddParam( theParams, "OZ")
165 << aCI.GetWorkingPlane(4) << " "
166 << aCI.GetWorkingPlane(5) << " "
167 << aCI.GetWorkingPlane(6);
168 AddParam( theParams, "OX")
169 << aCI.GetWorkingPlane(7) << " "
170 << aCI.GetWorkingPlane(8) << " "
171 << aCI.GetWorkingPlane(9);
174 AddParam( theParams, "Command", aCI.GetCommand() );
175 AddParam( theParams, "Working plane", aCI.GetWorkingPlane(), "XOY" );
184 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SketcherDriver,GEOM_BaseDriver);