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 <GEOMImpl_IMeasureOperations.hxx>
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include <BRep_Tool.hxx>
33 #include <Geom_Plane.hxx>
35 #include <TopoDS_Shape.hxx>
38 #include <Sketcher_Profile.hxx>
40 #include <Standard_ConstructionError.hxx>
42 //=======================================================================
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
48 static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
49 return aSketcherDriver;
53 //=======================================================================
54 //function : GEOMImpl_SketcherDriver
56 //=======================================================================
57 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
61 //=======================================================================
64 //=======================================================================
65 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
67 if (Label().IsNull()) return 0;
68 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70 GEOMImpl_ISketcher aCI (aFunction);
71 //Standard_Integer aType = aFunction->GetType();
73 // retrieve the command
74 TCollection_AsciiString aCommand = aCI.GetCommand();
75 if (aCommand.IsEmpty())
81 Sketcher_Profile aProfile (aCommand.ToCString());
83 if (!aProfile.IsDone()) {
84 Standard_ConstructionError::Raise("Sketcher creation failed");
87 aShape = aProfile.GetShape();
92 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
95 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
97 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
99 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
100 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
104 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
105 TopoDS_Shape aShape = aRefFace->GetValue();
106 //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
108 //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
109 //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
111 //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
112 //aWPlane = aGPlane->Pln().Position();
113 aWPlane = GEOMImpl_IMeasureOperations::GetPosition(aShape);
116 aTrans.SetTransformation(aWPlane);
118 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
119 aShape = aTransformation.Shape();
124 // set the function result
125 aFunction->SetValue(aShape);
127 log.SetTouched(Label());
133 //=======================================================================
134 //function : GEOMImpl_SketcherDriver_Type_
136 //=======================================================================
137 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
140 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
141 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
142 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
143 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
144 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
145 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
148 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
149 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
150 sizeof(GEOMImpl_SketcherDriver),
152 (Standard_Address)_Ancestors,
153 (Standard_Address)NULL);
158 //=======================================================================
159 //function : DownCast
161 //=======================================================================
162 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
164 Handle(GEOMImpl_SketcherDriver) _anOtherObject;
166 if (!AnObject.IsNull()) {
167 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
168 _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
172 return _anOtherObject ;