]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'BR_DEBIAN_RUNTIME' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Thu, 2 Apr 2015 11:01:28 +0000 (14:01 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 2 Apr 2015 11:01:28 +0000 (14:01 +0300)
24 files changed:
src/Model/Model_AttributeRefAttr.cpp
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_Document.cpp
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_Operation.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_Coincident.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp

index b6f9e3e67ee5fa6dffa1427c44f52232e1b5ddf3..2d900eb142221d089617a372e714d182ebf54aa2 100644 (file)
@@ -41,11 +41,29 @@ std::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
 
 void Model_AttributeRefAttr::setObject(ObjectPtr theObject)
 {
+  // the back reference from the previous object to the attribute should be removed
+  ObjectPtr anObject = object();
+  if (anObject.get() && anObject != theObject) {
+    FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+    if (anOwnerFeature.get()) {
+      std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+                                          anObject->data());
+      aData->removeBackReference(anOwnerFeature, id());
+    }
+  }
+
   if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) {
     std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
         theObject->data());
     myRef->Set(aData->label().Father());
     myID->Set("");  // feature is identified by the empty ID
+
+    // do it before the transaction finish to make just created/removed objects know dependencies
+    // and reference from composite feature is removed automatically
+    FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+    if (anOwnerFeature.get()) {
+      aData->addBackReference(anOwnerFeature, id(), false);
+    }
     owner()->data()->sendAttributeUpdated(this);
   } else if (theObject.get() == NULL) {
     myRef->Set(myRef->Label()); // reference to itself means that object is null
index b3baaea43867efe74c0fa09eef6c3a1e6f1b1b7f..e8c1a980ea406cd429c2d6f984c399216fba90ff 100644 (file)
@@ -259,9 +259,23 @@ void Model_Data::eraseBackReferences()
     aRes->setIsConcealed(false);
 }
 
+void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
+{
+  AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
+  if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
+    return;
+
+  myRefsToMe.erase(anAttribute);
+}
+
 void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID, 
    const bool theApplyConcealment)
 {
+  // do not add the same attribute twice
+  AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
+  if (myRefsToMe.find(anAttribute) != myRefsToMe.end())
+    return;
+
   myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
   if (theApplyConcealment && 
       ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
index 8a45cfe64bc5d8fecd62fb73db28049c2a9bde64..f3fd1c384e8dfa7c6704e0f3f9cf357e64bfa60a 100644 (file)
@@ -183,6 +183,11 @@ private:
   /// Removes all information about back references
   void eraseBackReferences();
   /// Adds a back reference (with identifier which attribute references to this object
+  /// It does not change the consealment flag of the data object result
+  /// \param theFeature feature referenced to this
+  /// \param theAttrID identifier of the attribute that is references from theFeature to this
+  void removeBackReference(FeaturePtr theFeature, std::string theAttrID);
+  /// Adds a back reference (with identifier which attribute references to this object
   /// \param theFeature feature referenced to this
   /// \param theAttrID identifier of the attribute that is references from theFeature to this
   /// \param theApplyConcealment applies consealment flag changes
index ee8cebc14c9d0274a1dd486a1638fca540450c17..754138db905803368bf2264f8e24df9db7b330dc 100644 (file)
@@ -696,6 +696,8 @@ void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck*
     }
     // event: feature is deleted
     ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
+    // the redisplay signal should be flushed in order to erase the feature presentation in the viewer
+    Events_Loop::loop()->flush(EVENT_DISP);
   }
 }
 
index c7cd377cc26d7c778d5c7f7e15f980043aa4fb01..1d68372056ca961735560524bc0ada42b8c2c029 100644 (file)
@@ -10,6 +10,7 @@
 \r
 #include <QString>\r
 #include <QObject>\r
+#include <QMap>\r
 \r
 #include <string>\r
 #include <map>\r
@@ -75,7 +76,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
 \r
   /// Add menu atems for viewer into the given menu\r
   /// \param theMenu a popup menu to be shown in the viewer\r
-  virtual void addViewerItems(QMenu* theMenu) const {}\r
+  /// \param theStdActions a map of standard actions\r
+  /// \return true if items are added and there is no necessity to provide standard menu\r
+  virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
 \r
   /// Add menu atems for object browser into the given menu\r
   /// \param theMenu a popup menu to be shown in the object browser\r
index ff2780957fc336c22171175d85433ee26ea824c0..084ba04bf563f555f4ad9d2bad5d631d6ba55f13 100644 (file)
@@ -220,6 +220,7 @@ void ModuleBase_Operation::activateByPreselection()
   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
   QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
   bool isSet = false;
+  // 1. apply the selection to controls
   for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
        (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
        ++aWIt) {
@@ -237,7 +238,15 @@ void ModuleBase_Operation::activateByPreselection()
       aFilledWgt = aWgt;
     }
   }
+  // 2. ignore not obligatory widgets
+  for (; aWIt != aWidgets.constEnd(); ++aWIt) {
+    aWgt = (*aWIt);
+    if (aWgt && aWgt->isObligatory())
+      continue;
+    aFilledWgt = aWgt;
+  }
 
+  // 3. activate the next obligatory widget
   myPropertyPanel->activateNextWidget(aFilledWgt);
   if (aFilledWgt)
     emit activatedByPreselection();
index 841387209216913943061197202e97cb03f22a97..4c685683578f2cd490d3964e314fca495da18414 100644 (file)
@@ -288,12 +288,12 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
   return aCanDisplay;
 }
 
-void PartSet_Module::addViewerItems(QMenu* theMenu) const
+bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
 {
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
       !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
-    return;
+    return false;
 
   ModuleBase_ISelection* aSelection = myWorkshop->selection();
   QObjectPtrList aObjects = aSelection->selectedPresentations();
@@ -307,10 +307,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const
       }
     }
     if (hasFeature) {
-      XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-      XGUI_Workshop* aWorkshop = aConnector->workshop();
-      QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
-      theMenu->addAction(anAction);
+      theMenu->addAction(theStdActions["DELETE_CMD"]);
     }
   }
   bool isAuxiliary;
@@ -319,6 +316,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const
     theMenu->addAction(anAction);
     anAction->setChecked(isAuxiliary);
   }
+  return true;
 }
 
 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
index 891759c36b34bb51dd9071fcc0bc70a7c449d280..5264352dc98b0563d12877f826f862cce2cd67dd 100644 (file)
@@ -103,7 +103,9 @@ public:
 
   /// Add menu atems for viewer into the given menu
   /// \param theMenu a popup menu to be shown in the viewer
-  virtual void addViewerItems(QMenu* theMenu) const;
+  /// \param theStdActions a map of standard actions
+  /// \return true if items are added and there is no necessity to provide standard menu
+  virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
 
 public slots:
   /// SLOT, that is called by no more widget signal emitted by property panel
index a92364d0594b30c0c7d950c77e94bfc4995f720a..82675355b292f78aeec6255f5ac6ad880d81757a 100644 (file)
@@ -431,19 +431,30 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2
   return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
 }
 
-ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
-                                                 const ObjectPtr& theObject, 
-                                                 CompositeFeaturePtr theSketch)
+ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
+                                                   const ObjectPtr& theObject,
+                                                   CompositeFeaturePtr theSketch)
 {
+  ResultPtr aResult;
   if (theShape.ShapeType() == TopAbs_EDGE) {
     // Check that we already have such external edge
     std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
     aInEdge->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalEdge(theSketch, aInEdge);
-    if (aResult)
-      return aResult;
+    aResult = findExternalEdge(theSketch, aInEdge);
+  }
+  if (theShape.ShapeType() == TopAbs_VERTEX) {
+    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
+    aInVert->setImpl(new TopoDS_Shape(theShape));
+    aResult = findExternalVertex(theSketch, aInVert);
+  }
+  return aResult;
+}
 
-    // If not found then we have to create new
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                                 const ObjectPtr& theObject, 
+                                                 CompositeFeaturePtr theSketch)
+{
+  if (theShape.ShapeType() == TopAbs_EDGE) {
     Standard_Real aStart, aEnd;
     Handle(V3d_View) aNullView;
     FeaturePtr aMyFeature;
@@ -487,12 +498,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
     }
   }
   if (theShape.ShapeType() == TopAbs_VERTEX) {
-    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
-    aInVert->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalVertex(theSketch, aInVert);
-    if (aResult)
-      return aResult;
-
     FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
 
     if (aMyFeature) {
index 854dd3b0eb1d5b5ae86e9c48bdf71b520ba75188..e614074a828550745b584f46ec607058121c9045 100644 (file)
@@ -145,6 +145,15 @@ class PARTSET_EXPORT PartSet_Tools
   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
                                                 CompositeFeaturePtr theSketch);
 
+  /// Finds a line (arc or circle) by given edge
+  /// \param theShape an edge
+  /// \param theObject a selected result object
+  /// \param theSketch a sketch feature
+  /// \return result of found feature or NULL
+  static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                             const ObjectPtr& theObject, 
+                                             CompositeFeaturePtr theSketch);
+
   /// Creates a line (arc or circle) by given edge
   /// Created line will have fixed constraint
   /// \param theShape an edge
index 5c5700b99f3e31663fc58d885ada99cd311bfa54..f3799357c04e50d0e89e1a89e1f1771f0ce6a5d3 100644 (file)
 
 bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
-  ObjectPtr aSelectedObject = theSelectedObject;
+  // initially the method is wrote to create an external object. Since the parent widget creates it,
+  // the redefinition is not necessary anymore.
+  // TODO: remove the widget and use the parent one insted of it
+  return PartSet_WidgetShapeSelector::setObject(theSelectedObject, theShape);
+  /*ObjectPtr aSelectedObject = theSelectedObject;
 
   FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
   if (aFeature) {
@@ -29,5 +33,5 @@ bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObjec
         return false;
     }
   }
-  return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
+  return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);*/
 }
index 4104331df0114782194ca1c48b9e04ee0eed99d7..10f6de95fd65dc663d5e28d6d00fcbcab2f4ebed 100644 (file)
@@ -262,8 +262,11 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
     if (aSelectedFeature.get() != NULL) {
       std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-      if ((!aSPFeature) && (!aShape.IsNull()))
-        PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      if ((!aSPFeature) && (!aShape.IsNull())) {
+        ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
+        if (!aFixedObject.get())
+          aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      }
     }
     double aX, aY;
     if (getPoint2d(aView, aShape, aX, aY)) {
index 3dc5460c20280216dde3d8f9f897c61ddaf30a62..cd659c04dc1aaac826683c67df61c3e6a167fe51 100644 (file)
@@ -15,6 +15,8 @@
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
+#include <SketchPlugin_ConstraintRigid.h>
+
 #include <XGUI_Workshop.h>
 
 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
@@ -36,12 +38,15 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
-    // Processing of external (non-sketch) object
-    createExternal(theSelectedObject, theShape);
-    if (myExternalObject)
-      aSelectedObject = myExternalObject;
-    else
-      return false;
+    aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                  theSelectedObject, mySketch);
+    if (!aSelectedObject.get()) {
+      // Processing of external (non-sketch) object
+      aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                  theSelectedObject, mySketch);
+      if (aSelectedObject.get())
+        myExternalObject = aSelectedObject;
+    }
   } else {
     // Processing of sketch object
     DataPtr aData = myFeature->data();
@@ -90,18 +95,6 @@ void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
   removeExternal();
 }
 
-//********************************************************************
-void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
-                                                 GeomShapePtr theShape)
-{
-  ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                              theSelectedObject, mySketch);
-  if (aObj != myExternalObject) {
-    removeExternal();
-    myExternalObject = aObj;
-  }
-}
-
 //********************************************************************
 void PartSet_WidgetShapeSelector::removeExternal()
 {
index e529e33ec5f45e122d69457f7739114cec4c4730..fb32bff9cc7242135412d6e1fc82a7b421395003 100644 (file)
@@ -54,11 +54,6 @@ protected:
   /// \param theValid a boolean flag, if restore happens for valid parameters
   void restoreAttributeValue(const bool theValid);
 
-  // Removes the external presentation from the model
-  /// \param theSelectedObject an object
-  /// \param theShape a selected shape, which is used in the selection attribute
-  void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
   // Removes the external presentation from the model
   void removeExternal();
 
index 23d1858b66b1d247a9da7c2f18a034e74c92f5dd..79cac01e7d10411a328c68a2db727a9f3eb7e2ae 100644 (file)
@@ -52,6 +52,7 @@ void SketchPlugin_ConstraintFillet::initAttributes()
 void SketchPlugin_ConstraintFillet::execute()
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
+  ResultConstructionPtr aRC;
   // Check the base objects are initialized
   double aFilletRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       aData->attribute(SketchPlugin_Constraint::VALUE()))->value();
@@ -65,12 +66,37 @@ void SketchPlugin_ConstraintFillet::execute()
   // Check the fillet shapes is not initialized yet
   AttributeRefListPtr aRefListOfFillet = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       aData->attribute(SketchPlugin_Constraint::ENTITY_C()));
-  if (aRefListOfFillet->size() > 0)
+  if (aRefListOfFillet->size() > 0) {
+    // update the Radius constraint
+    ObjectPtr aFilletArcObj = aRefListOfFillet->list().back();
+    aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFilletArcObj);
+    FeaturePtr aFilletArcFeature = aRC ? aRC->document()->feature(aRC) : 
+      std::dynamic_pointer_cast<ModelAPI_Feature>(aFilletArcObj);
+
+    int aNbSubs = sketch()->numberOfSubs();
+    FeaturePtr aSubFeature;
+    for (int aSub = 0; aSub < aNbSubs; aSub++) {
+      aSubFeature = sketch()->subFeature(aSub);
+      if (aSubFeature->getKind() != SketchPlugin_ConstraintRadius::ID())
+        continue;
+      AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          aSubFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      if (!aRefAttr || !aRefAttr->isObject())
+        continue;
+      aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRefAttr->object());
+      FeaturePtr aFeature = aRC ? aRC->document()->feature(aRC) : 
+        std::dynamic_pointer_cast<ModelAPI_Feature>(aRefAttr->object());
+      if (aFeature == aFilletArcFeature) {
+        AttributeDoublePtr aRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+            aSubFeature->attribute(SketchPlugin_Constraint::VALUE()));
+        aRadius->setValue(aFilletRadius);
+      }
+    }
     return;
+  }
   // Obtain features for the base objects
   FeaturePtr aFeatureA, aFeatureB;
-  ResultConstructionPtr aRC =
-      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseA->object());
+  aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseA->object());
   if (aRC) aFeatureA = aRC->document()->feature(aRC);
   aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseB->object());
   if (aRC) aFeatureB = aRC->document()->feature(aRC);
@@ -246,19 +272,18 @@ void SketchPlugin_ConstraintFillet::execute()
     ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
   }
 
-  // send events
-  ModelAPI_EventCreator::get()->sendUpdated(FeaturePtr(this), anUpdateEvent);
-  if (isUpdateFlushed)
-    Events_Loop::loop()->setFlushed(anUpdateEvent, true);
-  Events_Loop::loop()->flush(anUpdateEvent);
-
   // make base features auxiliary
   static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
   aFeatureA->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
   aFeatureB->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
   ModelAPI_EventCreator::get()->sendUpdated(aFeatureA, aRedisplayEvent);
   ModelAPI_EventCreator::get()->sendUpdated(aFeatureB, aRedisplayEvent);
-  Events_Loop::loop()->flush(aRedisplayEvent);
+////  Events_Loop::loop()->flush(aRedisplayEvent);
+
+  // send events
+  if (isUpdateFlushed)
+    Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+  Events_Loop::loop()->flush(anUpdateEvent);
 }
 
 AISObjectPtr SketchPlugin_ConstraintFillet::getAISObject(AISObjectPtr thePrevious)
index c7ee95fcc32070a00d6564cbb37effd8ad1f9870..e92cdb8c47472ae37d3726b24434f64d4743ca87 100644 (file)
@@ -55,6 +55,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_ExternalValidator);
   aFactory->registerValidator("SketchPlugin_TangentAttr",
                               new SketchPlugin_TangentAttrValidator);
+  aFactory->registerValidator("SketchPlugin_NotFixed",
+                              new SketchPlugin_NotFixedValidator);
+  aFactory->registerValidator("SketchPlugin_EqualAttr",
+                              new SketchPlugin_EqualAttrValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 358c82c1b4982e73bf8875c5e31b952798c55d16..95da79b9513deced964b1fd618ad7cab8ef9f6d2 100644 (file)
@@ -7,8 +7,10 @@
 #include "SketchPlugin_Validators.h"
 #include "SketchPlugin_ConstraintDistance.h"
 #include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintRigid.h"
 #include "SketchPlugin_Line.h"
 #include "SketchPlugin_Arc.h"
+#include "SketchPlugin_Circle.h"
 
 #include "SketcherPrs_Tools.h"
 
@@ -93,7 +95,8 @@ bool SketchPlugin_TangentAttrValidator::isValid(
       if (aOtherFea->getKind() != SketchPlugin_Arc::ID())
         return false;
     } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
-      if (aOtherFea->getKind() != SketchPlugin_Line::ID())
+      if (aOtherFea->getKind() != SketchPlugin_Line::ID() &&
+          aOtherFea->getKind() != SketchPlugin_Arc::ID())
         return false;
     } else
       return false;
@@ -135,4 +138,76 @@ bool SketchPlugin_TangentAttrValidator::isValid(
   return false;
 }
 
+bool SketchPlugin_NotFixedValidator::isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+  std::shared_ptr<SketchPlugin_Feature> aFeature =
+      std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+  if (!aFeature)
+    return true;
+
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+    return false;
+
+  SketchPlugin_Sketch* aSketch = aFeature->sketch();
+  int aNbFeatures = aSketch->numberOfSubs();
+  for (int anInd = 0; anInd < aNbFeatures; anInd++) {
+    FeaturePtr aSubFeature = aSketch->subFeature(anInd);
+    if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
+      continue;
+    AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
+    if (aRefAttr->isObject()) {
+      if (aRefAttr->object() == aRAttr->object())
+        return false;
+    } else if (aRefAttr->attr() == aRAttr->attr())
+      return false;
+  }
+  return true;
+}
+
+bool SketchPlugin_EqualAttrValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+  std::string aParamA = theArguments.front();
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeRefAttrPtr aRefAttr[2];
+  aRefAttr[0] = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+    return false;
+  aRefAttr[1] = aFeature->data()->refattr(aParamA);
+
+  if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject())
+    return false;
+
+  int aType[2] = {0, 0}; // types of attributes: 0 - incorrect, 1 - line, 2 - circle, 3 - arc
+  std::list<std::string> anArguments;
+  for (int i = 0; i < 2; i++) {
+    ObjectPtr anObject = aRefAttr[i]->object();
+    aFeature = ModelAPI_Feature::feature(anObject);
+    if (!aFeature)
+      return false;
+
+    if (aFeature->getKind() == SketchPlugin_Line::ID()) {
+      aType[i] = 1;
+      continue;
+    }
+    if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
+      aType[i] = 2;
+      continue;
+    }
+    if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
+      aType[i] = 3;
+      continue;
+    }
+    // wrong type of attribute
+    return false;
+  }
+
+  if ((aType[0] == 1 && aType[1] == 2) ||
+      (aType[0] == 2 && aType[1] == 1))
+    return false;
+  return true;
+}
 
index 11721fbd1dfd654190b980d2ea91f650b62943dc..47df3706156129b4cfacac9f4891d6bc0b733bc9 100644 (file)
@@ -44,4 +44,37 @@ class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator
 };
 
 
+/**\class SketchPlugin_NotFixed
+ * \ingroup Validators
+ * \brief Validator for the rigid constraint input.
+ *
+ * It just checks there is no rigid constraint for the current feature.
+ */
+class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is not used in another rigid constraint
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+};
+
+/**\class SketchPlugin_EqualAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the equal constraint input.
+ *
+ * It checks that attributes of the Equal constraint are correct.
+ */
+class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+};
+
+
 #endif
index 7274cc18dab72adb9939c9da12a5904ad506d7d5..caeb92d8d45f78528ad6fc4854d353f8f49fb901 100644 (file)
         <shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object" 
             shape_types="edge vertex">
           <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
+          <validator id="SketchPlugin_NotFixed"/>
         </shape_selector>
         <validator id="PartSet_RigidValidator"/>
       </feature>
       </feature>
       
     <!--  SketchConstraintEqual  -->
-      <feature id="SketchConstraintEqual" title="Equal" tooltip="Create constraint defining equality of two objects" icon=":icons/equal.png">
+      <feature id="SketchConstraintEqual" title="Equal"
+        tooltip="Create constraint defining equal lengths of two lines or line and arc or equal radii of two arcs or two circles or arc and circle"
+        icon=":icons/equal.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="First object" tooltip="Select line, circle or arc" shape_types="edge">
         </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB"
             label="Last object" tooltip="Select line, circle or arc" shape_types="edge">
-          <validator id="PartSet_SameTypeAttr" parameters="ConstraintEntityA"/>
+          <validator id="SketchPlugin_EqualAttr" parameters="ConstraintEntityA"/>
           <validator id="PartSet_DifferentObjects"/>
         </sketch_constraint_shape_selector>
       </feature>
             label="Last object" tooltip="Select line or arc" shape_types="edge">
         </sketch_constraint_shape_selector>
 
-        <doublevalue_editor label="Value" tooltip="Fillet radius" id="ConstraintValue" default="0" min="0">
+        <doublevalue_editor label="Value" tooltip="Fillet radius" id="ConstraintValue" default="1" min="0" obligatory="0">
           <validator id="GeomValidators_Positive"/>
         </doublevalue_editor>
       </feature>
index 2dc2db4ac2256ef63e172471aa4f7a38a61bee3b..fcdcf3617d8416f6ed3fbd4dead2fe5e96a8710e 100644 (file)
@@ -660,6 +660,22 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint(
 
   std::list<ObjectPtr> aBaseList = aBaseRefList->list();
   std::list<ObjectPtr> aMirroredList = aMirroredRefList->list();
+  // remove all empty items
+  std::list<ObjectPtr>::iterator anIt = aBaseList.begin();
+  std::list<ObjectPtr>::iterator aTmpIt;
+  while (anIt != aBaseList.end()) {
+    aTmpIt = anIt;
+    anIt++;
+    if (!(*aTmpIt))
+      aBaseList.erase(aTmpIt);
+  }
+  anIt = aMirroredList.begin();
+  while (anIt != aMirroredList.end()) {
+    aTmpIt = anIt;
+    anIt++;
+    if (!(*aTmpIt))
+      aMirroredList.erase(aTmpIt);
+  }
   if (aBaseList.empty() || aBaseList.size() != aMirroredList.size())
     return false;
 
index f98c29f7f3a083e7e2c8fece29ef786266e5377c..f7b61d9600c0fd5e2e53cc6b905efad7438b5bae 100644 (file)
@@ -23,6 +23,9 @@
 #include <Graphic3d_ArrayOfPoints.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Prs3d_Root.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Select3D_SensitivePoint.hxx>
 
 
 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
@@ -32,6 +35,7 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
 {
+  
 }  
 
 
@@ -46,11 +50,15 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
     return;
 
   std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
-
-  static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d ();
-  aPtA->SetType(Aspect_TOM_RING1);
-  aPtA->SetScale(2.);
-  aPtA->SetColor(myOwnColor);
+  myPoint = aPoint->impl<gp_Pnt>();
+
+  static Handle(Graphic3d_AspectMarker3d) aPtA;
+  if (aPtA.IsNull()) {
+    aPtA = new Graphic3d_AspectMarker3d ();
+    aPtA->SetType(Aspect_TOM_RING1);
+    aPtA->SetScale(2.);
+    aPtA->SetColor(myOwnColor);
+  }
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
   aGroup->SetPrimitivesAspect(aPtA);
   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
@@ -62,6 +70,9 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)&
 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                             const Standard_Integer aMode)
 {
+  Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
+  Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
+  aSelection->Add(aSp);
 }
 
 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
index 10d0c72c1553b47bba1b0acf80d241bf23953428..5aaf5d63589530db34843fe57517504a01cd1020 100644 (file)
@@ -46,6 +46,7 @@ protected:
 private:
   ModelAPI_Feature* myConstraint;
   std::shared_ptr<GeomAPI_Ax3> myPlane;
+  gp_Pnt myPoint;
 };
 
 
index 282b1a31cce1b9206fab121f02b79a98005e5d38..91d5c2f7cc99c9831aea1cf8e7e85844c6e57d5a 100644 (file)
@@ -227,40 +227,49 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const
 
 void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
 {
-  XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
-  QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
-  if (aObjects.size() > 0) {
-    //if (aObjects.size() == 1)
-    //  theMenu->addAction(action("EDIT_CMD"));
-    bool isVisible = false;
-    bool isShading = false;
-    bool canBeShaded = false;
-    foreach(ObjectPtr aObject, aObjects)
-    {
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
-      if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
-        isVisible = true;
-        canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
-        isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);      
-        break;
+  bool aIsDone = false;
+  ModuleBase_IModule* aModule = myWorkshop->module();
+  if (aModule) 
+    aIsDone = aModule->addViewerItems(theMenu, myActions);
+
+  if (!aIsDone) {
+    XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+    QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
+    if (aObjects.size() > 0) {
+      //if (aObjects.size() == 1)
+      //  theMenu->addAction(action("EDIT_CMD"));
+      bool isVisible = false;
+      bool isShading = false;
+      bool canBeShaded = false;
+      foreach(ObjectPtr aObject, aObjects)
+      {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+        if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
+          isVisible = true;
+          canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
+          isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);      
+          break;
+        }
       }
+      if (isVisible) {
+        if (canBeShaded) {
+          if (isShading)
+            theMenu->addAction(action("WIREFRAME_CMD"));
+          else
+            theMenu->addAction(action("SHADING_CMD"));
+        }
+        theMenu->addSeparator();
+        theMenu->addAction(action("SHOW_ONLY_CMD"));
+        theMenu->addAction(action("HIDE_CMD"));
+      } else
+        theMenu->addAction(action("SHOW_CMD"));
+      //theMenu->addAction(action("DELETE_CMD"));
     }
-    if (isVisible) {
-      if (canBeShaded) {
-        if (isShading)
-          theMenu->addAction(action("WIREFRAME_CMD"));
-        else
-          theMenu->addAction(action("SHADING_CMD"));
-      }
-      theMenu->addSeparator();
-      theMenu->addAction(action("SHOW_ONLY_CMD"));
-      theMenu->addAction(action("HIDE_CMD"));
-    } else
-      theMenu->addAction(action("SHOW_CMD"));
-    //theMenu->addAction(action("DELETE_CMD"));
+    if (myWorkshop->canChangeColor())
+      theMenu->addAction(action("COLOR_CMD"));
+    if (myWorkshop->displayer()->objectsCount() > 0)
+      theMenu->addAction(action("HIDEALL_CMD"));
   }
-  if (myWorkshop->displayer()->objectsCount() > 0)
-    theMenu->addAction(action("HIDEALL_CMD"));
   if (!myWorkshop->isSalomeMode()) {
     theMenu->addSeparator();
     QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
@@ -269,12 +278,7 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
       aSubMenu->addActions(aMDI->actions());
     }
   }
-  if (myWorkshop->canChangeColor())
-    theMenu->addAction(action("COLOR_CMD"));
 
-  ModuleBase_IModule* aModule = myWorkshop->module();
-  if (aModule)
-    aModule->addViewerItems(theMenu);
 }
 
 void XGUI_ContextMenuMgr::connectObjectBrowser() const
index 7498ab8317aadecd9375858cb631334984ddb6b4..5a6992d57646986c588f4211bba049ae6430f571 100644 (file)
@@ -562,8 +562,8 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
       // Redisplay the visible object or the object of the current operation
       bool isVisibleObject = myDisplayer->isVisible(aObj);
       #ifdef DEBUG_FEATURE_REDISPLAY
-      QString anObjInfo = objectInfo((aObj));
-      qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
+      //QString anObjInfo = objectInfo((aObj));
+      //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
       #endif
 
       if (isVisibleObject)  { // redisplay visible object
@@ -607,7 +607,11 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpd
   //bool aHasPart = false;
   bool isDisplayed = false;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
-
+    ObjectPtr anObject = *aIt;
+    // the validity of the data should be checked here in order to avoid display of the objects,
+    // which were created, then deleted, but flush for the creation event happens after that
+    if (!anObject->data() || !anObject->data()->isValid())
+      continue;
     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
     //if (aPart) {
       //aHasPart = true;