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_3DSketcherDriver.hxx>
24 #include <GEOMImpl_I3DSketcher.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <GEOMImpl_IMeasureOperations.hxx>
31 #include <BRepBuilderAPI_MakePolygon.hxx>
32 #include <BRepBuilderAPI_MakeVertex.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Wire.hxx>
38 #include <Standard_ConstructionError.hxx>
40 //=======================================================================
43 //=======================================================================
44 const Standard_GUID& GEOMImpl_3DSketcherDriver::GetID()
46 static Standard_GUID a3DSketcherDriver("FF2BBB54-5D24-4df3-210B-3A678263EA26");
47 return a3DSketcherDriver;
51 //=======================================================================
52 //function : GEOMImpl_3DSketcherDriver
54 //=======================================================================
55 GEOMImpl_3DSketcherDriver::GEOMImpl_3DSketcherDriver()
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer GEOMImpl_3DSketcherDriver::Execute(TFunction_Logbook& log) const
65 if (Label().IsNull()) return 0;
66 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
68 GEOMImpl_I3DSketcher aCI (aFunction);
72 Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates();
74 BRepBuilderAPI_MakePolygon aMakePoly;
75 int anArrayLength = aCoordsArray->Length();
78 for (int i = 0; i <=(anArrayLength - 3); i+=3) {
79 x = aCoordsArray->Value(i+1);
80 y = aCoordsArray->Value(i+2);
81 z = aCoordsArray->Value(i+3);
82 aPnt = gp_Pnt(x, y, z);
85 if ( anArrayLength == 3) { // Only Start Point
86 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
87 aShape = mkVertex.Shape();
90 if (aCoordsArray->Value(1) == x && aCoordsArray->Value(2) == y && aCoordsArray->Value(3) == z)
93 if (aMakePoly.IsDone())
94 aShape = aMakePoly.Wire();
97 if (aShape.IsNull()) return 0;
99 aFunction->SetValue(aShape);
100 log.SetTouched(Label());
105 //=======================================================================
106 //function : GEOMImpl_3DSketcherDriver_Type_
108 //=======================================================================
109 Standard_EXPORT Handle_Standard_Type& GEOMImpl_3DSketcherDriver_Type_()
112 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
113 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
114 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
115 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
116 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
117 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
120 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
121 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_3DSketcherDriver",
122 sizeof(GEOMImpl_3DSketcherDriver),
124 (Standard_Address)_Ancestors,
125 (Standard_Address)NULL);
130 //=======================================================================
131 //function : DownCast
133 //=======================================================================
134 const Handle(GEOMImpl_3DSketcherDriver) Handle(GEOMImpl_3DSketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
136 Handle(GEOMImpl_3DSketcherDriver) _anOtherObject;
138 if (!AnObject.IsNull()) {
139 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_3DSketcherDriver))) {
140 _anOtherObject = Handle(GEOMImpl_3DSketcherDriver)((Handle(GEOMImpl_3DSketcherDriver)&)AnObject);
144 return _anOtherObject ;