3 #include "GEOMImpl_SketcherDriver.hxx"
4 #include "GEOMImpl_ISketcher.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepBuilderAPI_Transform.hxx>
9 #include <BRep_Tool.hxx>
10 #include <Geom_Plane.hxx>
12 #include <TopoDS_Shape.hxx>
15 #include <Sketcher_Profile.hxx>
17 #include <Standard_ConstructionError.hxx>
19 //=======================================================================
22 //=======================================================================
23 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
25 static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
26 return aSketcherDriver;
30 //=======================================================================
31 //function : GEOMImpl_SketcherDriver
33 //=======================================================================
34 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
38 //=======================================================================
41 //=======================================================================
42 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
44 if (Label().IsNull()) return 0;
45 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
47 GEOMImpl_ISketcher aCI (aFunction);
48 //Standard_Integer aType = aFunction->GetType();
50 // retrieve the command
51 TCollection_AsciiString aCommand = aCI.GetCommand();
52 if (aCommand.IsEmpty())
58 Sketcher_Profile aProfile (aCommand.ToCString());
60 if (!aProfile.IsDone()) {
61 Standard_ConstructionError::Raise("Sketcher creation failed");
64 aShape = aProfile.GetShape();
69 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
72 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
74 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
76 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
77 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
81 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
82 TopoDS_Shape aShape = aRefFace->GetValue();
83 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
85 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
86 if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
88 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
89 aWPlane = aGPlane->Pln().Position();
92 aTrans.SetTransformation(aWPlane);
94 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
95 aShape = aTransformation.Shape();
100 // set the function result
101 aFunction->SetValue(aShape);
103 log.SetTouched(Label());
109 //=======================================================================
110 //function : GEOMImpl_SketcherDriver_Type_
112 //=======================================================================
113 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
116 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
117 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
118 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
119 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
120 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
121 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
124 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
125 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
126 sizeof(GEOMImpl_SketcherDriver),
128 (Standard_Address)_Ancestors,
129 (Standard_Address)NULL);
134 //=======================================================================
135 //function : DownCast
137 //=======================================================================
138 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
140 Handle(GEOMImpl_SketcherDriver) _anOtherObject;
142 if (!AnObject.IsNull()) {
143 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
144 _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
148 return _anOtherObject ;