From: nge Date: Fri, 23 Feb 2007 14:16:34 +0000 (+0000) Subject: PAL 12719 : Add an arc constructor X-Git-Tag: V3_2_6a1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=701f0a9674e7514ae359fc179bc468c2d7585a36;p=modules%2Fgeom.git PAL 12719 : Add an arc constructor --- diff --git a/src/GEOMImpl/GEOMImpl_ArcDriver.cxx b/src/GEOMImpl/GEOMImpl_ArcDriver.cxx index ded4e8b69..d25eb2199 100644 --- a/src/GEOMImpl/GEOMImpl_ArcDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ArcDriver.cxx @@ -35,12 +35,18 @@ #include #include - #include #include #include #include +#include +#include +#include +#include +#include + +#include "utilities.h" //======================================================================= //function : GetID //purpose : @@ -73,8 +79,7 @@ Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; - - if (aType == CIRC_ARC_THREE_PNT) { + if ((aType == CIRC_ARC_THREE_PNT)||(aType == CIRC_ARC_CENTER)) { Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); @@ -93,8 +98,28 @@ Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const Standard_ConstructionError::Raise("Arc creation aborted: coincident points given"); if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line"); - GC_MakeArcOfCircle arc (aP1, aP2, aP3); - aShape = BRepBuilderAPI_MakeEdge(arc).Edge(); + if (aType == CIRC_ARC_THREE_PNT){ + GC_MakeArcOfCircle arc(aP1, aP2, aP3); + aShape = BRepBuilderAPI_MakeEdge(arc).Edge(); + + } + if (aType == CIRC_ARC_CENTER){ + Standard_Real Rad = aP1.Distance(aP2); + gce_MakeCirc MC(aP1,gce_MakePln(aP1, aP2, aP3).Value(),Rad); + Standard_Boolean sense = aCI.GetSense(); + if (MC.IsDone()) { + const gp_Circ& Circ = MC.Value(); + Standard_Real Alpha1 = ElCLib::Parameter(Circ,aP2); + Standard_Real Alpha2 = ElCLib::Parameter(Circ,aP3); + Handle(Geom_Circle) C = new Geom_Circle(Circ); + Handle(Geom_TrimmedCurve) TheArc; + if (!sense) + TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,false); + if (sense) + TheArc= new Geom_TrimmedCurve(C,Alpha2,Alpha1,false); + aShape = BRepBuilderAPI_MakeEdge(TheArc).Edge(); + } + } } } else { } @@ -104,7 +129,7 @@ Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const aFunction->SetValue(aShape); log.SetTouched(Label()); - + MESSAGE("Out of building step ..."); return 1; } diff --git a/src/GEOMImpl/GEOMImpl_IArc.hxx b/src/GEOMImpl/GEOMImpl_IArc.hxx index 3c41b4c74..dc7372cd5 100644 --- a/src/GEOMImpl/GEOMImpl_IArc.hxx +++ b/src/GEOMImpl/GEOMImpl_IArc.hxx @@ -25,6 +25,7 @@ #define ARC_ARG_PI 1 #define ARC_ARG_PC 2 #define ARC_ARG_PE 3 +#define ARC_ARG_SE 4 class GEOMImpl_IArc { @@ -35,11 +36,13 @@ class GEOMImpl_IArc void SetPoint1(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PI, theP); } void SetPoint2(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PC, theP); } void SetPoint3(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PE, theP); } + void SetSense(bool theSense) { _func->SetInteger(ARC_ARG_SE, theSense); } Handle(GEOM_Function) GetPoint1() { return _func->GetReference(ARC_ARG_PI); } Handle(GEOM_Function) GetPoint2() { return _func->GetReference(ARC_ARG_PC); } Handle(GEOM_Function) GetPoint3() { return _func->GetReference(ARC_ARG_PE); } - + bool GetSense() { return _func->GetInteger(ARC_ARG_SE); } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index a28543ca7..3643e6f39 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -332,24 +332,25 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) the //Add a new Circle Arc function Handle(GEOM_Function) aFunction = - anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT); - if (aFunction.IsNull()) return NULL; + anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_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 @@ -374,6 +375,66 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) the 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; +} + //============================================================================= /*! * MakeSplineBezier diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index 0d6dbe97c..b0aa3cd39 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -51,6 +51,11 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) MakeArc (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2, Handle(GEOM_Object) thePnt3); + + Standard_EXPORT Handle(GEOM_Object) MakeArcCenter (Handle(GEOM_Object) thePnt1, + Handle(GEOM_Object) thePnt2, + Handle(GEOM_Object) thePnt3, + bool theSense); Standard_EXPORT Handle(GEOM_Object) MakeSplineBezier (list thePoints); Standard_EXPORT Handle(GEOM_Object) MakeSplineInterpolation (list thePoints); diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index c1c516fb7..897873d09 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -186,6 +186,7 @@ #define ELLIPSE_PNT_VEC_RR 1 #define CIRC_ARC_THREE_PNT 1 +#define CIRC_ARC_CENTER 2 #define FILLET_SHAPE_ALL 1 #define FILLET_SHAPE_EDGES 2 diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index d0c097ed4..ea89b3709 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -188,6 +188,43 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc return GetObject(anObject); } + +//============================================================================= +/*! + * MakeArcCenter + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcCenter + (GEOM::GEOM_Object_ptr thePnt1, + GEOM::GEOM_Object_ptr thePnt2, + GEOM::GEOM_Object_ptr thePnt3, + CORBA::Boolean theSense) + +{ + GEOM::GEOM_Object_var aGEOMObject; + //Set a not done flag + GetOperations()->SetNotDone(); + + if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn(); + + //Get the reference points + Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject + (thePnt1->GetStudyID(), thePnt1->GetEntry()); + Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject + (thePnt2->GetStudyID(), thePnt2->GetEntry()); + Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject + (thePnt3->GetStudyID(), thePnt3->GetEntry()); + + if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn(); + + // Make ArcCenter + Handle(GEOM_Object) anObject = + GetOperations()->MakeArcCenter(aPnt1, aPnt2, aPnt3,theSense); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} //============================================================================= /*! * MakePolyline diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.hh b/src/GEOM_I/GEOM_ICurvesOperations_i.hh index a22a595ea..300f6ae33 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.hh +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.hh @@ -54,7 +54,12 @@ class GEOM_ICurvesOperations_i : GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt3); - + + GEOM::GEOM_Object_ptr MakeArcCenter (GEOM::GEOM_Object_ptr thePnt1, + GEOM::GEOM_Object_ptr thePnt2, + GEOM::GEOM_Object_ptr thePnt3, + bool theSense); + GEOM::GEOM_Object_ptr MakePolyline (const GEOM::ListOfGO& thePoints); GEOM::GEOM_Object_ptr MakeSplineBezier (const GEOM::ListOfGO& thePoints); diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 6d289ff68..c67fb1735 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -2134,6 +2134,22 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeArc (GEOM::GEOM_Object_ptr thePnt1, return anObj; } +//============================================================================= +// MakeArcCenter: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeArcCenter (GEOM::GEOM_Object_ptr theCenter, + GEOM::GEOM_Object_ptr thePnt1, + GEOM::GEOM_Object_ptr thePnt2, + CORBA::Boolean theSense) +{ + beginService( " GEOM_Superv_i::MakeArcCenter" ); + MESSAGE("GEOM_Superv_i::MakeArcCenter"); + getCurvesOp(); + GEOM::GEOM_Object_ptr anObj = myCurvesOp->MakeArcCenter(theCenter, thePnt1, thePnt2,theSense); + endService( " GEOM_Superv_i::MakeArcCenter" ); + return anObj; +} + //============================================================================= // MakePolyline: //============================================================================= diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index 4dce89ebb..1d8f5b94c 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -468,6 +468,10 @@ public: GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt3); + GEOM::GEOM_Object_ptr MakeArcCenter (GEOM::GEOM_Object_ptr theCenter, + GEOM::GEOM_Object_ptr thePnt1, + GEOM::GEOM_Object_ptr thePnt2, + CORBA::Boolean theSense); GEOM::GEOM_Object_ptr MakePolyline (GEOM::GEOM_List_ptr thePoints); GEOM::GEOM_Object_ptr MakeSplineBezier (GEOM::GEOM_List_ptr thePoints); GEOM::GEOM_Object_ptr MakeSplineInterpolation (GEOM::GEOM_List_ptr thePoints); diff --git a/src/GEOM_SWIG/GEOM_TestAll.py b/src/GEOM_SWIG/GEOM_TestAll.py index ec0670186..a044befec 100644 --- a/src/GEOM_SWIG/GEOM_TestAll.py +++ b/src/GEOM_SWIG/GEOM_TestAll.py @@ -84,6 +84,7 @@ def TestAll (geompy, math): Plane1 = geompy.MakePlaneThreePnt(px, pz, p200, trimsize) #(4 Doubles)->GEOM_Object_ptr Arc = geompy.MakeArc(py, pz, px) #(3 GEOM_Object_ptr)->GEOM_Object_ptr + Arc2 = geompy.MakeArcCenter(py, pz, px,0) #(3 GEOM_Object_ptr,Boolean)->GEOM_Object_ptr Circle = geompy.MakeCircle(p0, vz, radius1) #(2 GEOM_Object_ptr, Double)->GEOM_Object_ptr Circle1 = geompy.MakeCircleThreePnt(p0, pxyz, px) #(3 GEOM_Object_ptr)->GEOM_Object_ptr Ellipse = geompy.MakeEllipse(p0, vy, radius2, radius1) #(2 GEOM_Object_ptr, 2 Doubles)->GEOM_Object_ptr diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 428939deb..8d1eefd88 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -339,6 +339,19 @@ def MakeArc(thePnt1, thePnt2, thePnt3): print "MakeArc : ", CurvesOp.GetErrorCode() return anObj +## Create an arc of circle from a center and 2 points. +# @param thePnt1 Center of the arc +# @param thePnt2 Start point of the arc. (Gives also the radius of the arc) +# @param thePnt3 End point of the arc (Gives also a direction) +# @return New GEOM_Object, containing the created arc. +# +# Example: see GEOM_TestAll.py +def MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense): + anObj = CurvesOp.MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense) + if CurvesOp.IsDone() == 0: + print "MakeArcCenter : ", CurvesOp.GetErrorCode() + return anObj + ## Create a circle with given center, normal vector and radius. # @param thePnt Circle center. # @param theVec Vector, normal to the plane of the circle.