1 // Copyright (C) 2007-2008 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.
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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_SketcherDriver.hxx>
25 #include <GEOMImpl_ISketcher.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <GEOMImpl_IMeasureOperations.hxx>
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <BRep_Tool.hxx>
34 #include <Geom_Plane.hxx>
36 #include <TopoDS_Shape.hxx>
39 #include <Sketcher_Profile.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(TFunction_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())
82 Sketcher_Profile aProfile (aCommand.ToCString());
84 if (!aProfile.IsDone()) {
85 Standard_ConstructionError::Raise("Sketcher creation failed");
88 aShape = aProfile.GetShape();
93 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
96 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
98 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
100 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
101 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
105 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
106 TopoDS_Shape aShape = aRefFace->GetValue();
107 //if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
109 //Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
110 //if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
112 //Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
113 //aWPlane = aGPlane->Pln().Position();
114 aWPlane = GEOMImpl_IMeasureOperations::GetPosition(aShape);
117 aTrans.SetTransformation(aWPlane);
119 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
120 aShape = aTransformation.Shape();
125 // set the function result
126 aFunction->SetValue(aShape);
128 log.SetTouched(Label());
134 //=======================================================================
135 //function : GEOMImpl_SketcherDriver_Type_
137 //=======================================================================
138 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
141 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
142 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
143 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
144 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
145 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
146 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
149 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
150 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
151 sizeof(GEOMImpl_SketcherDriver),
153 (Standard_Address)_Ancestors,
154 (Standard_Address)NULL);
159 //=======================================================================
160 //function : DownCast
162 //=======================================================================
163 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
165 Handle(GEOMImpl_SketcherDriver) _anOtherObject;
167 if (!AnObject.IsNull()) {
168 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
169 _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
173 return _anOtherObject ;