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 <GC_MakeArcOfCircle.hxx>
#include <Standard_ConstructionError.hxx>
#include <Precision.hxx>
#include <gp_Pnt.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
//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;
}

View File

@ -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,10 +36,12 @@ 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:

View File

@ -332,18 +332,19 @@ 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);
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);
@ -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

View File

@ -52,6 +52,11 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations {
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<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 CIRC_ARC_THREE_PNT 1
#define CIRC_ARC_CENTER 2
#define FILLET_SHAPE_ALL 1
#define FILLET_SHAPE_EDGES 2

View File

@ -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

View File

@ -55,6 +55,11 @@ class GEOM_ICurvesOperations_i :
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);

View File

@ -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:
//=============================================================================

View File

@ -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);

View File

@ -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

View File

@ -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.