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();
72 int anArrayLength = aCoordsArray->Length();
74 std::list<gp_Pnt> points;
76 for (int i = 0; i <= (anArrayLength-3); i += 3) {
77 gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3));
78 if (points.empty() || aPnt.Distance(points.back()) > gp::Resolution())
79 points.push_back(aPnt);
82 if ( points.size() == 1) { // Only Start Point
83 BRepBuilderAPI_MakeVertex mkVertex (points.back());
84 aShape = mkVertex.Shape();
86 else if ( points.size() > 1) { // Make Wire
87 BRepBuilderAPI_MakePolygon aMakePoly;
88 std::list<gp_Pnt>::iterator it;
89 for (it = points.begin(); it != points.end(); ++it) {
93 if (points.size() > 2 &&
94 points.back().X() == points.front().X() &&
95 points.back().Y() == points.front().Y() &&
96 points.back().Z() == points.front().Z())
99 if (aMakePoly.IsDone())
100 aShape = aMakePoly.Wire();
103 if (aShape.IsNull()) return 0;
105 aFunction->SetValue(aShape);
106 log.SetTouched(Label());
111 //=======================================================================
112 //function : GEOMImpl_3DSketcherDriver_Type_
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOMImpl_3DSketcherDriver_Type_()
118 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
119 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
120 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
121 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
122 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
123 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
126 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
127 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_3DSketcherDriver",
128 sizeof(GEOMImpl_3DSketcherDriver),
130 (Standard_Address)_Ancestors,
131 (Standard_Address)NULL);
136 //=======================================================================
137 //function : DownCast
139 //=======================================================================
140 const Handle(GEOMImpl_3DSketcherDriver) Handle(GEOMImpl_3DSketcherDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 Handle(GEOMImpl_3DSketcherDriver) _anOtherObject;
144 if (!AnObject.IsNull()) {
145 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_3DSketcherDriver))) {
146 _anOtherObject = Handle(GEOMImpl_3DSketcherDriver)((Handle(GEOMImpl_3DSketcherDriver)&)AnObject);
150 return _anOtherObject ;