2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_SketcherDriver.hxx>
5 #include <GEOMImpl_ISketcher.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepBuilderAPI_Transform.hxx>
10 #include <BRep_Tool.hxx>
11 #include <Geom_Plane.hxx>
13 #include <TopoDS_Shape.hxx>
16 #include <Sketcher_Profile.hxx>
18 #include <Standard_ConstructionError.hxx>
20 //=======================================================================
23 //=======================================================================
24 const Standard_GUID& GEOMImpl_SketcherDriver::GetID()
26 static Standard_GUID aSketcherDriver("FF1BBB64-5D14-4df2-980B-3A668264EA16");
27 return aSketcherDriver;
31 //=======================================================================
32 //function : GEOMImpl_SketcherDriver
34 //=======================================================================
35 GEOMImpl_SketcherDriver::GEOMImpl_SketcherDriver()
39 //=======================================================================
42 //=======================================================================
43 Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
45 if (Label().IsNull()) return 0;
46 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
48 GEOMImpl_ISketcher aCI (aFunction);
49 //Standard_Integer aType = aFunction->GetType();
51 // retrieve the command
52 TCollection_AsciiString aCommand = aCI.GetCommand();
53 if (aCommand.IsEmpty())
59 Sketcher_Profile aProfile (aCommand.ToCString());
61 if (!aProfile.IsDone()) {
62 Standard_ConstructionError::Raise("Sketcher creation failed");
65 aShape = aProfile.GetShape();
70 if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS )
73 gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3));
75 gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6));
77 gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9));
78 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
82 Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane();
83 TopoDS_Shape aShape = aRefFace->GetValue();
84 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE )
86 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ));
87 if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane )))
89 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
90 aWPlane = aGPlane->Pln().Position();
93 aTrans.SetTransformation(aWPlane);
95 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
96 aShape = aTransformation.Shape();
101 // set the function result
102 aFunction->SetValue(aShape);
104 log.SetTouched(Label());
110 //=======================================================================
111 //function : GEOMImpl_SketcherDriver_Type_
113 //=======================================================================
114 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SketcherDriver_Type_()
117 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
118 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
119 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
120 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
121 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
122 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
125 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
126 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SketcherDriver",
127 sizeof(GEOMImpl_SketcherDriver),
129 (Standard_Address)_Ancestors,
130 (Standard_Address)NULL);
135 //=======================================================================
136 //function : DownCast
138 //=======================================================================
139 const Handle(GEOMImpl_SketcherDriver) Handle(GEOMImpl_SketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
141 Handle(GEOMImpl_SketcherDriver) _anOtherObject;
143 if (!AnObject.IsNull()) {
144 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SketcherDriver))) {
145 _anOtherObject = Handle(GEOMImpl_SketcherDriver)((Handle(GEOMImpl_SketcherDriver)&)AnObject);
149 return _anOtherObject ;