Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 16 Apr 2015 14:45:37 +0000 (17:45 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 16 Apr 2015 14:45:37 +0000 (17:45 +0300)
14 files changed:
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
src/Model/Model_Document.cpp
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ParametersPlugin/ParametersPlugin_Parameter.cpp
src/ParametersPlugin/ParametersPlugin_PyInterp.cpp
src/ParametersPlugin/ParametersPlugin_PyInterp.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Solver.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SketchSolver_Storage.h

index e3d7eb34c4f58e7f2edf07b540e17386bf62c61a..ae24aaf3c7916561f9de78cd36f8dfdbc6dcbf69 100644 (file)
@@ -59,6 +59,19 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
   }
 }
 
+void ConstructionPlugin_Axis::createAxisByCylindricalFace()
+{
+    std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
+     // update arguments due to the selection value
+    if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
+
+      ResultConstructionPtr aConstr = document()->createConstruction(data());
+      aConstr->setShape(anEdge);
+      setResult(aConstr);
+    }
+}
+
 void ConstructionPlugin_Axis::execute()
 {
   AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
@@ -66,14 +79,12 @@ void ConstructionPlugin_Axis::execute()
   if (aMethodType == "AxisByPointsCase") {
     createAxisByTwoPoints();
   } else if (aMethodType == "AxisByCylindricalFaceCase") {
-    #ifdef _DEBUG
-    std::cout << "ConstructionPlugin_Axis::execute: " << "AxisByCylindricalFaceCase is not supported yet." << std::endl;
-    #endif
+    createAxisByCylindricalFace();
   }
 }
 
 bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                                    std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+  std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
   bool isCustomized = theDefaultPrs.get() != NULL &&
                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
index df8aedcfde5bf9fd4d32414aaf67557dc7f554f2..1775300ebda82e65cbdd043fdc84073e78d6eb35 100644 (file)
@@ -78,6 +78,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
 
  protected:
   void createAxisByTwoPoints();
+  void createAxisByCylindricalFace();
 };
 
 
index f1ecb2b34fca5e14775253030ec483e616639460..0de55a60f36502506bd813eb21528fe3398daf64 100644 (file)
@@ -8,9 +8,11 @@
 #include <gp_Pln.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
+#include <Geom_CylindricalSurface.hxx>
 
 #include <gp_Ax2.hxx>
 #include <gp_Circ.hxx>
@@ -32,6 +34,36 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
   return aRes;
 }
 
+std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
+    std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
+{
+  std::shared_ptr<GeomAPI_Edge> aResult;
+  const TopoDS_Shape& aShape = theCylindricalFace->impl<TopoDS_Shape>();
+  if (aShape.IsNull())
+    return aResult;
+  TopoDS_Face aFace = TopoDS::Face(aShape);
+  if (aFace.IsNull())
+    return aResult;
+  TopLoc_Location aLoc;
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
+  if (aSurf.IsNull())
+    return aResult;
+  Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
+  if (aCyl.IsNull())
+    return aResult;
+  gp_Ax1 anAxis = aCyl->Axis();
+  gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation()));
+  // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder
+  gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.);
+  anEnd.Transform(aLoc.Transformation());
+  
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+  std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
+
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
     std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
     double theRadius)
index ef0f82df49d04931d80d748a35c2667dcc4232e6..0bd67621bc66ffeeb8b0b286949902e7a87f9dfe 100644 (file)
@@ -23,7 +23,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
  public:
   /// Creates linear edge by two points
   static std::shared_ptr<GeomAPI_Edge> line(std::shared_ptr<GeomAPI_Pnt> theStart,
-                                              std::shared_ptr<GeomAPI_Pnt> theEnd);
+                                            std::shared_ptr<GeomAPI_Pnt> theEnd);
+  /// Creates edge - axis of the given cylindrical face
+  static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
+    std::shared_ptr<GeomAPI_Shape> theCylindricalFace);
 
   /// Creates linear edge in a form of a circle by a point and a circle radius
   static std::shared_ptr<GeomAPI_Edge> lineCircle(std::shared_ptr<GeomAPI_Pnt> theCenter,
index ec0c236f6f0389ab60177023a65ab8e30a399696..c2321d59b7c39baf1715d214fe3db425d7944b15 100644 (file)
@@ -1300,6 +1300,9 @@ void Model_Document::updateResults(FeaturePtr theFeature)
           break;
         } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
           aNewBody = createGroup(theFeature->data(), aResIndex);
+        } else if (aGroup->Get() == ModelAPI_ResultParameter::group().c_str()) {
+          theFeature->attributeChanged("expression"); // just produce a value
+          break;
         } else {
           Events_Error::send(std::string("Unknown type of result is found in the document:") +
             TCollection_AsciiString(aGroup->Get()).ToCString());
index 57e21b80b345375dec256c0fe0109f6260bf5957..925b1cc94c8508545041d6b63677ae962331aa76 100644 (file)
@@ -256,5 +256,7 @@ void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e)
 void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent)
 {
   ModuleBase_DoubleSpinBox::showEvent(theEvent);
-  //setText(myTextValue);
+  if (hasVariable(myTextValue)) {
+    setText(myTextValue);
+  }
 }
index a17ea26c9793ee4a8c3acab86dc7f5df40b0646b..551f9e7c8bfa2afa74aba0b190e449790bd122eb 100644 (file)
@@ -96,12 +96,11 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 
 void ModuleBase_WidgetDoubleValue::reset()
 {
-  if (isComputedDefault()) {
+  if (isComputedDefault() || mySpinBox->hasVariable()) {
     return;
     //if (myFeature->compute(myAttributeID))
     //  restoreValue();
-  }
-  else {
+  } else {
     bool isOk;
     double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
     // reset the value just if there is a default value definition in the XML definition
@@ -121,6 +120,8 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
   std::string aTextRepr = aReal->text();
   if (mySpinBox->hasVariable()) {
     aTextRepr = mySpinBox->text().toStdString();
+  } else {
+    aTextRepr = "";
   }
   aReal->setText(aTextRepr);
   updateObject(myFeature);
index 70840ccff61641a071de1ab711ca1ba972df0a98..48f5d731236e99c4d008b66a7bccb0206c73d53f 100644 (file)
@@ -18,6 +18,7 @@
 ParametersPlugin_Parameter::ParametersPlugin_Parameter()
 {
   myInterp = new ParametersPlugin_PyInterp();
+  myInterp->initialize();
 }
 
 ParametersPlugin_Parameter::~ParametersPlugin_Parameter()
@@ -76,7 +77,7 @@ void ParametersPlugin_Parameter::execute()
 
 double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError)
 {
-  myInterp->initialize();
+
   std::list<std::string> anExprParams = myInterp->compile(theExpression);
   // find expression's params in the model
   std::list<std::string> aContext;
@@ -92,6 +93,6 @@ double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, st
   }
   myInterp->extendLocalContext(aContext);
   double result = myInterp->evaluate(theExpression, theError);
-  myInterp->destroy();
+  myInterp->clearLocalContext();
   return result;
 }
index 7a5f42c4fe5243e9abf000951c50ce36971aded1..4afbfaa2a93f75a404e12d1f7cd57c2dd6bb12ee 100644 (file)
@@ -69,6 +69,12 @@ void ParametersPlugin_PyInterp::extendLocalContext(const std::list<std::string>&
   }
 }
 
+void ParametersPlugin_PyInterp::clearLocalContext()
+{
+  PyLockWrapper lck;
+  PyDict_Clear(_local_context);
+}
+
 
 double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression, std::string& theError)
 {
index 4151f4e231cf192a3dd18c3cb26b06b7db318dd0..0e3cdee56401f7819ae60e5d31ce7a63102f2a99 100644 (file)
@@ -22,6 +22,7 @@ class PARAMETERSPLUGIN_EXPORT ParametersPlugin_PyInterp : public PyInterp_Interp
 
   std::list<std::string> compile(const std::string&);
   void extendLocalContext(const std::list<std::string>&);
+  void clearLocalContext();
   double evaluate(const std::string&, std::string&);
 
  protected:
index a7f8d5b4801a50a90785797741ac02d5f0a4cc0f..e630978ecc48952bde87291222a7b16f1104b44a 100644 (file)
@@ -411,8 +411,18 @@ bool SketchSolver_Group::resolveConstraints()
     try {
       if (myStorage->hasDuplicatedConstraint())
         aResult = SLVS_RESULT_INCONSISTENT;
-      else
-        aResult = myConstrSolver.solve();
+      else {
+        // To avoid overconstraint situation, we will remove temporary constraints one-by-one
+        // and try to find the case without overconstraint
+        int aNbTemp = (int)myTempConstraints.size();
+        while (true) {
+          aResult = myConstrSolver.solve();
+          if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0)
+            break;
+          aNbTemp = myStorage->removeFirstTemporaryConstraint();
+          myStorage->initializeSolver(myConstrSolver);
+        }
+      }
     } catch (...) {
       Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
       return false;
index 0e7b1761cc51e62b2aeeede9ce12c1c952d9f51c..4e7a4f0e9269f7e2d76ad8219a130fce099864f3 100644 (file)
@@ -63,8 +63,10 @@ void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int th
     myEquationsSystem.constraints = theSize;
   }
   else if (myEquationsSystem.constraints != theSize) {
-    delete[] myEquationsSystem.constraint;
-    myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+    if (theSize > myEquationsSystem.constraints) {
+      delete[] myEquationsSystem.constraint;
+      myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+    }
     myEquationsSystem.constraints = theSize;
   }
   memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint));
index 1d5a8332d882f8a59259e275af2b74e57080e417..250ce7e564e1fb49ae4c8f463727631a0da19c27 100644 (file)
@@ -546,6 +546,15 @@ void SketchSolver_Storage::removeTemporaryConstraints()
   myTemporaryConstraints.clear();
 }
 
+int SketchSolver_Storage::removeFirstTemporaryConstraint()
+{
+  if (myTemporaryConstraints.empty())
+    return 0;
+  removeConstraint(*myTemporaryConstraints.begin());
+  myTemporaryConstraints.erase(myTemporaryConstraints.begin());
+  return (int)myTemporaryConstraints.size();
+}
+
 bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const
 {
   return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end();
index fbd9acf6412592b1382e64ac107e60c142edc8fe..fc2e46ceba6963d96d58325fa7d780bcad72a184 100644 (file)
@@ -108,6 +108,9 @@ public:
   void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
   /// \brief Remove all transient constraints
   void removeTemporaryConstraints();
+  /// \brief Remove first temporary constraint
+  /// \return Number of remaining temporary constraints
+  int removeFirstTemporaryConstraint();
   /// \brief Checks the constraint is temporary
   bool isTemporary(const Slvs_hConstraint& theConstraintID) const;