PAL 12719 : Add an arc constructor

This commit is contained in:
nge 2007-02-23 14:16:34 +00:00
parent a7ee4904f5
commit 701f0a9674
11 changed files with 183 additions and 12 deletions

View File

@ -35,12 +35,18 @@
#include <TopExp.hxx> #include <TopExp.hxx>
#include <GC_MakeArcOfCircle.hxx> #include <GC_MakeArcOfCircle.hxx>
#include <Standard_ConstructionError.hxx> #include <Standard_ConstructionError.hxx>
#include <Precision.hxx> #include <Precision.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <gp_Vec.hxx> #include <gp_Vec.hxx>
#include <gce_MakeCirc.hxx>
#include <gce_MakePln.hxx>
#include <ElCLib.hxx>
#include <Geom_Circle.hxx>
#include <Geom_TrimmedCurve.hxx>
#include "utilities.h"
//======================================================================= //=======================================================================
//function : GetID //function : GetID
//purpose : //purpose :
@ -73,8 +79,7 @@ Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
Standard_Integer aType = aFunction->GetType(); Standard_Integer aType = aFunction->GetType();
TopoDS_Shape aShape; TopoDS_Shape aShape;
if ((aType == CIRC_ARC_THREE_PNT)||(aType == CIRC_ARC_CENTER)) {
if (aType == CIRC_ARC_THREE_PNT) {
Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); 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"); Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line"); Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
GC_MakeArcOfCircle arc (aP1, aP2, aP3); if (aType == CIRC_ARC_THREE_PNT){
aShape = BRepBuilderAPI_MakeEdge(arc).Edge(); 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 { } else {
} }
@ -104,7 +129,7 @@ Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
aFunction->SetValue(aShape); aFunction->SetValue(aShape);
log.SetTouched(Label()); log.SetTouched(Label());
MESSAGE("Out of building step ...");
return 1; return 1;
} }

View File

@ -25,6 +25,7 @@
#define ARC_ARG_PI 1 #define ARC_ARG_PI 1
#define ARC_ARG_PC 2 #define ARC_ARG_PC 2
#define ARC_ARG_PE 3 #define ARC_ARG_PE 3
#define ARC_ARG_SE 4
class GEOMImpl_IArc class GEOMImpl_IArc
{ {
@ -35,11 +36,13 @@ class GEOMImpl_IArc
void SetPoint1(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PI, theP); } 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 SetPoint2(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PC, theP); }
void SetPoint3(Handle(GEOM_Function) theP) { _func->SetReference(ARC_ARG_PE, 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) GetPoint1() { return _func->GetReference(ARC_ARG_PI); }
Handle(GEOM_Function) GetPoint2() { return _func->GetReference(ARC_ARG_PC); } Handle(GEOM_Function) GetPoint2() { return _func->GetReference(ARC_ARG_PC); }
Handle(GEOM_Function) GetPoint3() { return _func->GetReference(ARC_ARG_PE); } Handle(GEOM_Function) GetPoint3() { return _func->GetReference(ARC_ARG_PE); }
bool GetSense() { return _func->GetInteger(ARC_ARG_SE); }
private: private:
Handle(GEOM_Function) _func; Handle(GEOM_Function) _func;

View File

@ -332,24 +332,25 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) the
//Add a new Circle Arc function //Add a new Circle Arc function
Handle(GEOM_Function) aFunction = Handle(GEOM_Function) aFunction =
anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT); anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
if (aFunction.IsNull()) return NULL;
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly //Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL; if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
GEOMImpl_IArc aCI (aFunction); GEOMImpl_IArc aCI (aFunction);
Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction(); Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction(); Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction(); Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL; if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
aCI.SetPoint1(aRefPnt1); aCI.SetPoint1(aRefPnt1);
aCI.SetPoint2(aRefPnt2); aCI.SetPoint2(aRefPnt2);
aCI.SetPoint3(aRefPnt3); aCI.SetPoint3(aRefPnt3);
//Compute the Arc value //Compute the Arc value
try { try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 #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; 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 * MakeSplineBezier

View File

@ -51,6 +51,11 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakeArc (Handle(GEOM_Object) thePnt1, Standard_EXPORT Handle(GEOM_Object) MakeArc (Handle(GEOM_Object) thePnt1,
Handle(GEOM_Object) thePnt2, Handle(GEOM_Object) thePnt2,
Handle(GEOM_Object) thePnt3); 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<Handle(GEOM_Object)> thePoints); Standard_EXPORT Handle(GEOM_Object) MakeSplineBezier (list<Handle(GEOM_Object)> thePoints);
Standard_EXPORT Handle(GEOM_Object) MakeSplineInterpolation (list<Handle(GEOM_Object)> thePoints); Standard_EXPORT Handle(GEOM_Object) MakeSplineInterpolation (list<Handle(GEOM_Object)> thePoints);

View File

@ -186,6 +186,7 @@
#define ELLIPSE_PNT_VEC_RR 1 #define ELLIPSE_PNT_VEC_RR 1
#define CIRC_ARC_THREE_PNT 1 #define CIRC_ARC_THREE_PNT 1
#define CIRC_ARC_CENTER 2
#define FILLET_SHAPE_ALL 1 #define FILLET_SHAPE_ALL 1
#define FILLET_SHAPE_EDGES 2 #define FILLET_SHAPE_EDGES 2

View File

@ -188,6 +188,43 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
return GetObject(anObject); 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 * MakePolyline

View File

@ -54,7 +54,12 @@ class GEOM_ICurvesOperations_i :
GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1,
GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt2,
GEOM::GEOM_Object_ptr thePnt3); 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 MakePolyline (const GEOM::ListOfGO& thePoints);
GEOM::GEOM_Object_ptr MakeSplineBezier (const GEOM::ListOfGO& thePoints); GEOM::GEOM_Object_ptr MakeSplineBezier (const GEOM::ListOfGO& thePoints);

View File

@ -2134,6 +2134,22 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeArc (GEOM::GEOM_Object_ptr thePnt1,
return anObj; 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: // MakePolyline:
//============================================================================= //=============================================================================

View File

@ -468,6 +468,10 @@ public:
GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1,
GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt2,
GEOM::GEOM_Object_ptr thePnt3); 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 MakePolyline (GEOM::GEOM_List_ptr thePoints);
GEOM::GEOM_Object_ptr MakeSplineBezier (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); GEOM::GEOM_Object_ptr MakeSplineInterpolation (GEOM::GEOM_List_ptr thePoints);

View File

@ -84,6 +84,7 @@ def TestAll (geompy, math):
Plane1 = geompy.MakePlaneThreePnt(px, pz, p200, trimsize) #(4 Doubles)->GEOM_Object_ptr 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 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 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 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 Ellipse = geompy.MakeEllipse(p0, vy, radius2, radius1) #(2 GEOM_Object_ptr, 2 Doubles)->GEOM_Object_ptr

View File

@ -339,6 +339,19 @@ def MakeArc(thePnt1, thePnt2, thePnt3):
print "MakeArc : ", CurvesOp.GetErrorCode() print "MakeArc : ", CurvesOp.GetErrorCode()
return anObj 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. ## Create a circle with given center, normal vector and radius.
# @param thePnt Circle center. # @param thePnt Circle center.
# @param theVec Vector, normal to the plane of the circle. # @param theVec Vector, normal to the plane of the circle.