geom/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx

918 lines
28 KiB
C++
Raw Normal View History

2009-02-13 17:16:39 +05:00
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2005-12-05 21:23:52 +05:00
//
2009-02-13 17:16:39 +05:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2005-12-05 21:23:52 +05:00
//
2009-02-13 17:16:39 +05:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2005-12-05 21:23:52 +05:00
//
2005-08-11 10:43:57 +06:00
#include <Standard_Stream.hxx>
2004-12-01 15:39:14 +05:00
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_ICurvesOperations.hxx>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <TColStd_HArray1OfReal.hxx>
2005-08-11 10:43:57 +06:00
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_Types.hxx>
2004-12-01 15:39:14 +05:00
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_PolylineDriver.hxx>
#include <GEOMImpl_CircleDriver.hxx>
#include <GEOMImpl_SplineDriver.hxx>
#include <GEOMImpl_EllipseDriver.hxx>
#include <GEOMImpl_ArcDriver.hxx>
#include <GEOMImpl_SketcherDriver.hxx>
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_3DSketcherDriver.hxx>
2004-12-01 15:39:14 +05:00
2005-08-11 10:43:57 +06:00
#include <GEOMImpl_IPolyline.hxx>
#include <GEOMImpl_ICircle.hxx>
#include <GEOMImpl_ISpline.hxx>
#include <GEOMImpl_IEllipse.hxx>
#include <GEOMImpl_IArc.hxx>
#include <GEOMImpl_ISketcher.hxx>
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_I3DSketcher.hxx>
2004-12-01 15:39:14 +05:00
#include "utilities.h"
#include <TDF_Tool.hxx>
#include <Standard_Failure.hxx>
2004-12-01 15:39:14 +05:00
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//=============================================================================
/*!
* constructor:
*/
//=============================================================================
GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
: GEOM_IOperations(theEngine, theDocID)
{
MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
}
//=============================================================================
/*!
* destructor
*/
//=============================================================================
GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
{
MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
}
//=============================================================================
/*!
* MakePolyline
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
{
SetErrorCode(KO);
//Add a new Polyline object
Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
//Add a new Polyline function for creation a polyline relatively to points set
Handle(GEOM_Function) aFunction =
aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
GEOMImpl_IPolyline aCI (aFunction);
int aLen = thePoints.size();
aCI.SetLength(aLen);
int ind = 1;
list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
for (; it != thePoints.end(); it++, ind++) {
Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
if (aRefPnt.IsNull()) {
SetErrorCode("NULL point for Polyline");
return NULL;
}
aCI.SetPoint(ind, aRefPnt);
}
//Compute the Polyline value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Polyline driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << aPolyline << " = geompy.MakePolyline([";
2004-12-01 15:39:14 +05:00
it = thePoints.begin();
pd << (*it++);
while (it != thePoints.end()) {
pd << ", " << (*it++);
2004-12-01 15:39:14 +05:00
}
pd << "])";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aPolyline;
}
//=============================================================================
/*!
* MakeCircleThreePnt
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3)
{
SetErrorCode(KO);
if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
//Add a new Circle object
Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
//Add a new Circle function for creation a circle relatively to three points
Handle(GEOM_Function) aFunction =
aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
GEOMImpl_ICircle aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
//Compute the Circle value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Circle driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
<< thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aCircle;
}
//=============================================================================
/*!
* MakeCircleCenter2Pnt
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3)
{
SetErrorCode(KO);
if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
//Add a new Circle object
Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
//Add a new Circle function for creation a circle relatively to center and 2 points
Handle(GEOM_Function) aFunction =
aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
GEOMImpl_ICircle aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
//Compute the Circle value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Circle driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
<< thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
SetErrorCode(OK);
return aCircle;
}
2004-12-01 15:39:14 +05:00
//=============================================================================
/*!
* MakeCirclePntVecR
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
(Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
{
SetErrorCode(KO);
2009-02-13 17:16:39 +05:00
// Not set thePnt means origin of global CS,
// Not set theVec means Z axis of global CS
//if (thePnt.IsNull() || theVec.IsNull()) return NULL;
2004-12-01 15:39:14 +05:00
//Add a new Circle object
Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
//Add a new Circle function for creation a circle relatively to point and vector
Handle(GEOM_Function) aFunction =
aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
GEOMImpl_ICircle aCI (aFunction);
2009-02-13 17:16:39 +05:00
if (!thePnt.IsNull()) {
Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
if (aRefPnt.IsNull()) return NULL;
aCI.SetCenter(aRefPnt);
}
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (!theVec.IsNull()) {
Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
if (aRefVec.IsNull()) return NULL;
aCI.SetVector(aRefVec);
}
2004-12-01 15:39:14 +05:00
aCI.SetRadius(theR);
//Compute the Circle value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Circle driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
<< thePnt << ", " << theVec << ", " << theR << ")";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aCircle;
}
//=============================================================================
/*!
* MakeEllipse
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
(Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
double theRMajor, double theRMinor,
2009-12-25 16:28:58 +05:00
Handle(GEOM_Object) theVecMaj)
2004-12-01 15:39:14 +05:00
{
SetErrorCode(KO);
2009-02-13 17:16:39 +05:00
// Not set thePnt means origin of global CS,
// Not set theVec means Z axis of global CS
// Not set theVecMaj means X axis of global CS
2009-02-13 17:16:39 +05:00
//if (thePnt.IsNull() || theVec.IsNull()) return NULL;
2004-12-01 15:39:14 +05:00
//Add a new Ellipse object
Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
//Add a new Ellipse function
Handle(GEOM_Function) aFunction =
anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
GEOMImpl_IEllipse aCI (aFunction);
2009-02-13 17:16:39 +05:00
if (!thePnt.IsNull()) {
Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
if (aRefPnt.IsNull()) return NULL;
aCI.SetCenter(aRefPnt);
}
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if (!theVec.IsNull()) {
Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
if (aRefVec.IsNull()) return NULL;
aCI.SetVector(aRefVec);
}
2004-12-01 15:39:14 +05:00
aCI.SetRMajor(theRMajor);
aCI.SetRMinor(theRMinor);
if (!theVecMaj.IsNull()) {
Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
if (aRefVecMaj.IsNull()) return NULL;
aCI.SetVectorMajor(aRefVecMaj);
}
2004-12-01 15:39:14 +05:00
//Compute the Ellipse value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Ellipse driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
if (!theVecMaj.IsNull()) {
GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
2009-12-25 16:28:58 +05:00
<< thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
<< ", " << theVecMaj << ")";
}
else {
GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
2009-12-25 16:28:58 +05:00
<< thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
}
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return anEll;
}
//=============================================================================
/*!
* MakeArc
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3)
{
SetErrorCode(KO);
if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
//Add a new Circle Arc object
Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
//Add a new Circle Arc function
Handle(GEOM_Function) aFunction =
anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
2004-12-01 15:39:14 +05:00
if (aFunction.IsNull()) return NULL;
2004-12-01 15:39:14 +05:00
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
2004-12-01 15:39:14 +05:00
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
2004-12-01 15:39:14 +05:00
//Compute the Arc value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Arc driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
<< thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return anArc;
}
//=============================================================================
/*!
* MakeArcCenter
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3,
bool theSense)
{
SetErrorCode(KO);
if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
//Add a new Circle Arc object
Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
//Add a new Circle Arc function
Handle(GEOM_Function) aFunction =
anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
aCI.SetSense(theSense);
//Compute the Arc value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Arc driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
<< thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
SetErrorCode(OK);
return anArc;
}
2009-02-13 17:16:39 +05:00
//=============================================================================
/*!
* MakeArcOfEllipse
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
2009-12-25 16:28:58 +05:00
Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3)
2009-02-13 17:16:39 +05:00
{
SetErrorCode(KO);
if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
//Add a new Circle Arc object
Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
//Add a new Circle Arc function
Handle(GEOM_Function) aFunction =
anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3);
//Compute the Arc value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Arc driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
<< thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
SetErrorCode(OK);
return anArc;
}
2004-12-01 15:39:14 +05:00
//=============================================================================
/*!
* MakeSplineBezier
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
(list<Handle(GEOM_Object)> thePoints)
{
SetErrorCode(KO);
//Add a new Spline object
Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
//Add a new Spline function for creation a bezier curve relatively to points set
Handle(GEOM_Function) aFunction =
aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
GEOMImpl_ISpline aCI (aFunction);
int aLen = thePoints.size();
aCI.SetLength(aLen);
int ind = 1;
list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
for (; it != thePoints.end(); it++, ind++) {
Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
if (aRefPnt.IsNull()) return NULL;
aCI.SetPoint(ind, aRefPnt);
}
//Compute the Spline value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Spline driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << aSpline << " = geompy.MakeBezier([";
2004-12-01 15:39:14 +05:00
it = thePoints.begin();
pd << (*it++);
while (it != thePoints.end()) {
pd << ", " << (*it++);
2004-12-01 15:39:14 +05:00
}
pd << "])";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aSpline;
}
//=============================================================================
/*!
* MakeSplineInterpolation
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
(list<Handle(GEOM_Object)> thePoints,
bool theIsClosed)
2004-12-01 15:39:14 +05:00
{
SetErrorCode(KO);
//Add a new Spline object
Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
//Add a new Spline function for creation a bezier curve relatively to points set
Handle(GEOM_Function) aFunction =
aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
GEOMImpl_ISpline aCI (aFunction);
int aLen = thePoints.size();
aCI.SetLength(aLen);
int ind = 1;
list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
for (; it != thePoints.end(); it++, ind++) {
Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
if (aRefPnt.IsNull()) return NULL;
aCI.SetPoint(ind, aRefPnt);
}
aCI.SetIsClosed(theIsClosed);
2004-12-01 15:39:14 +05:00
//Compute the Spline value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Spline driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << aSpline << " = geompy.MakeInterpol([";
2004-12-01 15:39:14 +05:00
it = thePoints.begin();
pd << (*it++);
while (it != thePoints.end()) {
pd << ", " << (*it++);
2004-12-01 15:39:14 +05:00
}
pd << "])";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aSpline;
}
//=============================================================================
/*!
* MakeSketcher
*/
//=============================================================================
2009-02-13 17:16:39 +05:00
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
2009-12-25 16:28:58 +05:00
list<double> theWorkingPlane)
2004-12-01 15:39:14 +05:00
{
SetErrorCode(KO);
2009-02-13 17:16:39 +05:00
if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
2004-12-01 15:39:14 +05:00
//Add a new Sketcher object
Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
//Add a new Sketcher function
Handle(GEOM_Function) aFunction =
aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
2004-12-01 15:39:14 +05:00
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
GEOMImpl_ISketcher aCI (aFunction);
2009-02-13 17:16:39 +05:00
TCollection_AsciiString aCommand((char*) theCommand);
aCI.SetCommand(aCommand);
2004-12-01 15:39:14 +05:00
int ind = 1;
list<double>::iterator it = theWorkingPlane.begin();
for (; it != theWorkingPlane.end(); it++, ind++)
aCI.SetWorkingPlane(ind, *it);
//Compute the Sketcher value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
2004-12-01 15:39:14 +05:00
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Sketcher driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump pd (aFunction);
2009-02-13 17:16:39 +05:00
pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
2004-12-01 15:39:14 +05:00
it = theWorkingPlane.begin();
pd << (*it++);
while (it != theWorkingPlane.end()) {
pd << ", " << (*it++);
2004-12-01 15:39:14 +05:00
}
pd << "])";
2004-12-01 15:39:14 +05:00
SetErrorCode(OK);
return aSketcher;
}
2009-02-13 17:16:39 +05:00
//=============================================================================
/*!
* Make3DSketcher
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (list<double> theCoordinates)
{
SetErrorCode(KO);
//Add a new Sketcher object
Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
//Add a new Sketcher function
Handle(GEOM_Function) aFunction =
a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
GEOMImpl_I3DSketcher aCI (aFunction);
int nbOfCoords = 0;
list<double>::iterator it = theCoordinates.begin();
for (; it != theCoordinates.end(); it++)
nbOfCoords++;
Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
it = theCoordinates.begin();
int ind = 1;
for (; it != theCoordinates.end(); it++, ind++)
aCoordsArray->SetValue(ind, *it);
aCI.SetCoordinates(aCoordsArray);
//Compute the Sketcher value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("3D Sketcher driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump pd (aFunction);
pd << a3DSketcher << " = geompy.Make3DSketcher([";
it = theCoordinates.begin();
pd << (*it++);
while (it != theCoordinates.end()) {
pd << ", " << (*it++);
}
pd << "])";
SetErrorCode(OK);
return a3DSketcher;
}
//=============================================================================
/*!
* MakeSketcherOnPlane
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
2009-02-13 17:16:39 +05:00
(const char* theCommand,
Handle(GEOM_Object) theWorkingPlane)
{
SetErrorCode(KO);
2009-02-13 17:16:39 +05:00
if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
//Add a new Sketcher object
Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
//Add a new Sketcher function
Handle(GEOM_Function) aFunction =
aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
GEOMImpl_ISketcher aCI (aFunction);
2009-02-13 17:16:39 +05:00
TCollection_AsciiString aCommand((char*) theCommand);
aCI.SetCommand(aCommand);
Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
if (aRefPlane.IsNull()) return NULL;
aCI.SetWorkingPlane( aRefPlane );
//Compute the Sketcher value
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Sketcher driver failed");
return NULL;
}
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode(aFail->GetMessageString());
return NULL;
}
//Make a Python command
GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
2009-02-13 17:16:39 +05:00
<< aCommand.ToCString() << "\", " << theWorkingPlane << " )";
SetErrorCode(OK);
return aSketcher;
}