Salome HOME
PAL 12719 : Add an arc constructor
authornge <nge>
Fri, 23 Feb 2007 14:16:34 +0000 (14:16 +0000)
committernge <nge>
Fri, 23 Feb 2007 14:16:34 +0000 (14:16 +0000)
src/GEOMImpl/GEOMImpl_ArcDriver.cxx
src/GEOMImpl/GEOMImpl_IArc.hxx
src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx
src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx
src/GEOMImpl/GEOMImpl_Types.hxx
src/GEOM_I/GEOM_ICurvesOperations_i.cc
src/GEOM_I/GEOM_ICurvesOperations_i.hh
src/GEOM_I_Superv/GEOM_Superv_i.cc
src/GEOM_I_Superv/GEOM_Superv_i.hh
src/GEOM_SWIG/GEOM_TestAll.py
src/GEOM_SWIG/geompy.py

index ded4e8b69e913df9bebd84f816fd7f210c0ee1fe..d25eb21991c69afa9213c43b5c0ffa641b727024 100644 (file)
 #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;    
 }
 
index 3c41b4c7404801dfc4cbe92356b74ecc483bed6f..dc7372cd5c0bb764fbf18a715f8756eebd6dcd89 100644 (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,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;
index a28543ca7154fca165f80842fa50db9b875f6837..3643e6f39072cfcf7d669f202063ea33b3c8897d 100644 (file)
@@ -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
index 0d6dbe97cdccebbd0684da56ffe24209505aea15..b0aa3cd39b579192e3583a29f1ba6bb54db86ba7 100644 (file)
@@ -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<Handle(GEOM_Object)> thePoints);
   Standard_EXPORT Handle(GEOM_Object) MakeSplineInterpolation (list<Handle(GEOM_Object)> thePoints);
index c1c516fb73a566976f39651ae9b063c63c424617..897873d097c220357535128b9afbc67bb9f5a88c 100755 (executable)
 #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
index d0c097ed463756859ceef01766c1bdf16846d517..ea89b37092885c20d87bdf74e6b067d4bb58991b 100644 (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
index a22a595ea235fa69bd89b9942c2b426d5aac9a67..300f6ae3379eeafdecf6b2f85800e692280e662c 100644 (file)
@@ -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);
index 6d289ff684e0f5f9dae0322148ca218f629b9443..c67fb1735ac1471b74ce33efd7d31a4b516e828e 100644 (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:
 //=============================================================================
index 4dce89ebb6a98c24f4f1daf0a9397ae72e58abb4..1d8f5b94cacdd4b01a2c1b00f6c58a9feff47ad4 100644 (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);
index ec06701863af3e9c873725b8bf564da5cca2944e..a044befec569c5af172c3c90844eefaccd61b355 100644 (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
index 428939debb067781c41a9b55e83fcb4329ba85dc..8d1eefd887b9adf8bc9302527776b008cdb85cbe 100644 (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.