1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_SketcherDriver.hxx>
24 #include <GEOMImpl_ISketcher.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_Transform.hxx>
29 #include <BRep_Tool.hxx>
30 #include <Geom_Plane.hxx>
32 #include <TopoDS_Shape.hxx>
35 #include <Sketcher_Profile.hxx>
37 #include <Standard_ConstructionError.hxx>
39 //=======================================================================
42 //=======================================================================
43 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
45 static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
46 return aSketcherDriver;
50 //=======================================================================
51 //function : GEOMImpl_SketcherDriver
53 //=======================================================================
54 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
58 //=======================================================================
61 //=======================================================================
62 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
64 if (Label().IsNull()) return 0;
65 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67 GEOMImpl_ISketcher aCI (aFunction);
68 //Standard_Integer aType = aFunction->GetType();
70 // retrieve the command
71 TCollection_AsciiString aCommand = aCI.GetCommand();
72 if (aCommand.IsEmpty())
78 Sketcher_Profile aProfile (aCommand.ToCString());
80 if (!aProfile.IsDone()) {
81 Standard_ConstructionError::Raise("Sketcher creation failed");
84 aShape = aProfile.GetShape();
89 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
92 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
94 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
96 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
97 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
101 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
102 TopoDS_Shape aShape = aRefFace->GetValue();
103 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
105 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
106 if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
108 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
109 aWPlane = aGPlane->Pln().Position();
112 aTrans.SetTransformation(aWPlane);
114 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
115 aShape = aTransformation.Shape();
120 // set the function result
121 aFunction->SetValue(aShape);
123 log.SetTouched(Label());
129 //=======================================================================
130 //function : GEOMImpl_SketcherDriver_Type_
132 //=======================================================================
133 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
136 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
137 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
138 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
139 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
140 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
141 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
144 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
145 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
146 sizeof(GEOMImpl_SketcherDriver),
148 (Standard_Address)_Ancestors,
149 (Standard_Address)NULL);
154 //=======================================================================
155 //function : DownCast
157 //=======================================================================
158 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
160 Handle(GEOMImpl_SketcherDriver) _anOtherObject;
162 if (!AnObject.IsNull()) {
163 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
164 _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
168 return _anOtherObject ;