1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_3DSketcherDriver.hxx>
23 #include <GEOMImpl_I3DSketcher.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
27 #include <GEOMImpl_IMeasureOperations.hxx>
30 #include <BRepBuilderAPI_MakePolygon.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Wire.hxx>
37 #include <Standard_ConstructionError.hxx>
39 //=======================================================================
42 //=======================================================================
43 const Standard_GUID& GEOMImpl_3DSketcherDriver::GetID()
45 static Standard_GUID a3DSketcherDriver("FF2BBB54-5D24-4df3-210B-3A678263EA26");
46 return a3DSketcherDriver;
50 //=======================================================================
51 //function : GEOMImpl_3DSketcherDriver
53 //=======================================================================
54 GEOMImpl_3DSketcherDriver::GEOMImpl_3DSketcherDriver()
58 //=======================================================================
61 //=======================================================================
62 Standard_Integer GEOMImpl_3DSketcherDriver::Execute(TFunction_Logbook& log) const
64 if (Label().IsNull()) return 0;
65 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67 GEOMImpl_I3DSketcher aCI (aFunction);
71 Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates();
73 BRepBuilderAPI_MakePolygon aMakePoly;
74 int anArrayLength = aCoordsArray->Length();
77 for (int i = 0; i <=(anArrayLength - 3); i+=3) {
78 x = aCoordsArray->Value(i+1);
79 y = aCoordsArray->Value(i+2);
80 z = aCoordsArray->Value(i+3);
81 aPnt = gp_Pnt(x, y, z);
84 if ( anArrayLength == 3) { // Only Start Point
85 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
86 aShape = mkVertex.Shape();
89 if (aCoordsArray->Value(1) == x && aCoordsArray->Value(2) == y && aCoordsArray->Value(3) == z)
92 if (aMakePoly.IsDone())
93 aShape = aMakePoly.Wire();
96 if (aShape.IsNull()) return 0;
98 aFunction->SetValue(aShape);
99 log.SetTouched(Label());
104 //=======================================================================
105 //function : GEOMImpl_3DSketcherDriver_Type_
107 //=======================================================================
108 Standard_EXPORT Handle_Standard_Type& GEOMImpl_3DSketcherDriver_Type_()
111 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
112 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
113 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
114 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
115 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
116 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
119 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
120 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_3DSketcherDriver",
121 sizeof(GEOMImpl_3DSketcherDriver),
123 (Standard_Address)_Ancestors,
124 (Standard_Address)NULL);
129 //=======================================================================
130 //function : DownCast
132 //=======================================================================
133 const Handle(GEOMImpl_3DSketcherDriver) Handle(GEOMImpl_3DSketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
135 Handle(GEOMImpl_3DSketcherDriver) _anOtherObject;
137 if (!AnObject.IsNull()) {
138 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_3DSketcherDriver))) {
139 _anOtherObject = Handle(GEOMImpl_3DSketcherDriver)((Handle(GEOMImpl_3DSketcherDriver)&)AnObject);
143 return _anOtherObject ;