Salome HOME
Added 2 new operations:
[modules/geom.git] / src / GEOMImpl / GEOMImpl_I3DPrimOperations.cxx
index cbadd3a4996d9cd6e4e636ab8e3add3e1e53c63a..76962b98879182ce76db5fd8324549fcb3ed839b 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <Standard_Stream.hxx>
 
-#include <CASCatch_OCCTVersion.hxx>
+#include <Basics_OCCTVersion.hxx>
 
 #include <GEOMImpl_I3DPrimOperations.hxx>
 
@@ -1293,6 +1293,88 @@ Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ2Ways
   return aPrism;
 }
 
+//=============================================================================
+/*!
+ *  MakeDraftPrism
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDraftPrism
+       (Handle(GEOM_Object) theInitShape ,Handle(GEOM_Object) theBase, double theHeight, double theAngle, bool theFuse)
+{
+  SetErrorCode(KO);
+
+  if (theBase.IsNull() || theInitShape.IsNull()) return NULL;
+
+  Handle(GEOM_Object) aPrism = NULL;
+  
+  if ( theFuse )
+  {
+    //Add a new Extruded Boss object  
+    aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_BOSS);
+  }
+  else
+  { 
+    //Add a new Extruded Cut object  
+    aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_CUT);
+  }
+  
+  //Add a new Prism function for the creation of a Draft Prism feature
+  Handle(GEOM_Function) aFunction = 
+    aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), DRAFT_PRISM_FEATURE);
+  if (aFunction.IsNull()) return NULL;
+  
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
+  
+  GEOMImpl_IPrism aCI (aFunction);
+
+  Handle(GEOM_Function) aRefInit = theInitShape->GetLastFunction();
+  Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
+  if (aRefBase.IsNull() || aRefInit.IsNull()) return NULL;
+  
+  // Set parameters 
+  aCI.SetBase(aRefBase);
+  aCI.SetInitShape(aRefInit);
+  aCI.SetH(theHeight);
+  aCI.SetDraftAngle(theAngle);
+  if ( theFuse )
+    aCI.SetFuseFlag(1);
+  else
+    aCI.SetFuseFlag(0);
+  
+  //Compute the Draft Prism Feature value
+  try {
+#if OCC_VERSION_LARGE > 0x06010000
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Extrusion can not be created, check input data");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+  
+  //Make a Python command
+  if(theFuse)
+  {
+    GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakeExtrudedBoss("
+      << theInitShape << ", " << theBase << ", " << theHeight << ", " << theAngle << ")";
+  }
+  else
+  {   
+    GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakeExtrudedCut("
+      << theInitShape << ", " << theBase << ", " << theHeight << ", " << theAngle << ")";
+  }
+
+  SetErrorCode(OK);
+  return aPrism;
+}
+
 //=============================================================================
 /*!
  *  MakePipe
@@ -1404,7 +1486,7 @@ Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(
 
   //Make a Python command
   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
-    << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
+    << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
 
   SetErrorCode(OK);
   return aRevolution;
@@ -1462,7 +1544,7 @@ Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle2Ways
 
   //Make a Python command
   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution2Ways("
-    << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
+    << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
 
   SetErrorCode(OK);
   return aRevolution;