Salome HOME
Merge branch 'master' of newgeom:newgeom
authorszy <szy@opencascade.com>
Fri, 31 Oct 2014 08:33:22 +0000 (11:33 +0300)
committerszy <szy@opencascade.com>
Fri, 31 Oct 2014 08:33:22 +0000 (11:33 +0300)
44 files changed:
env_Salome.bat
src/FeaturesPlugin/FeaturesPlugin_Group.cpp
src/FeaturesPlugin/FeaturesPlugin_Group.h
src/Model/CMakeLists.txt
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Data.h
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultGroup.cpp [new file with mode: 0644]
src/Model/Model_ResultGroup.h [new file with mode: 0644]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_ResultGroup.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_Operation.cpp
src/NewGeom/NewGeom_DataModel.cpp
src/NewGeom/NewGeom_SalomeViewer.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationFeatureEdit.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSetPlugin/PartSetPlugin_Duplicate.h
src/PartSetPlugin/PartSetPlugin_Plugin.cpp
src/PartSetPlugin/plugin-PartSet.xml
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_DocumentDataModel.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_Preferences.cpp
src/XGUI/XGUI_RubberBand.cpp
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 98d24b244d4e0ef6de974f96f2d881e4989535aa..ffad9939b00fed2da1f8575426baac8882dc0011 100644 (file)
@@ -75,6 +75,7 @@ rem @SET PATH=%SOLVESPACE_ROOT_DIR%\lib;%PATH%
 
 @SET PATH=%GEOM_ROOT_DIR%\lib\salome;%PATH%
 
+@SET _NO_DEBUG_HEAP=1
 
 IF "%ARCH%" == "Win64" (
   call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" x64
index dad22dbf60b9ec8b537c3aa1b2bc2e2f82cc206d..e9ae74d59627fda00bc49c8bebdb64bed2021025 100644 (file)
@@ -25,10 +25,7 @@ void FeaturesPlugin_Group::initAttributes()
 
 void FeaturesPlugin_Group::execute()
 {
-  //AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
-  //    data()->attribute(FeaturesPlugin_Group::NAME_ID()));
-  //if (!aNameAttr)
-  //  return;
-  //std::string aName = aNameAttr->value();
-  //data()->setName(aName);
+  if (results().empty()) { // just create result if not exists
+    document()->createGroup(data());
+  }
 }
index 23078ae675c99b4b299724592b471d1930c182f3..7138c1241ca0a298c6199878f6e2b658a4ea5e4c 100644 (file)
@@ -44,6 +44,9 @@ class FeaturesPlugin_Group : public ModelAPI_Feature
   /// Request for initialization of data model of the feature: adding all attributes
   FEATURESPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Result of groups is created on the fly and don't stored to the document
+  FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
   /// Use plugin manager for features creation
   FeaturesPlugin_Group();
 
index 1656a618f50738db0746fba46fc4ff0b86b23908..753fd7817bd14c5ae8a34540513e7a195f95a24a 100644 (file)
@@ -22,6 +22,7 @@ SET(PROJECT_HEADERS
     Model_ResultBody.h
     Model_ResultConstruction.h
     Model_ResultPart.h
+    Model_ResultGroup.h
     Model_FeatureValidator.h
 )
 
@@ -46,6 +47,7 @@ SET(PROJECT_SOURCES
     Model_ResultBody.cpp
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
+    Model_ResultGroup.cpp
     Model_FeatureValidator.cpp
 )
 
index f502aee03ba59f3ce286eebee36505058ad38da9..dd360d258474f4baf9e732802c6eff3e5940511b 100644 (file)
@@ -21,6 +21,7 @@
 #include <TNaming_Builder.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TDataStd_IntPackedMap.hxx>
+#include <TDataStd_Integer.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TDF_LabelMap.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS.hxx>
 #include <TColStd_MapOfTransient.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
 
 using namespace std;
+/// adeed to the index in the packed map to signalize that the vertex of edge is seleted
+/// (multiplied by the index of the edge)
+static const int kSTART_VERTEX_DELTA = 1000000;
+
+// on this label is stored:
+// TNaming_NamedShape - selected shape
+// TNaming_Naming - topological selection information (for the body)
+// TDataStd_IntPackedMap - indexes of edges in composite element (for construction)
+// TDataStd_Integer - type of the selected shape (for construction)
+// TDF_Reference - from ReferenceAttribute, the context
 
 void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
@@ -91,88 +104,167 @@ bool Model_AttributeSelection::update()
     // body: just a named shape, use selection mechanism from OCCT
     TNaming_Selector aSelector(selectionLabel());
     TDF_LabelMap aScope; // empty means the whole document
+    owner()->data()->sendAttributeUpdated(this);
     return aSelector.Solve(aScope) == Standard_True;
-   
   } else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
     // construction: identification by the results indexes, recompute faces and
     // take the face that more close by the indexes
-    boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
+    boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
+      boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
       boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext)->shape());
     if (aWirePtr && aWirePtr->hasPlane()) {
-        // If this is a wire with plane defined thin it is a sketch-like object
-      std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-      GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
-        aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
-      if (aFaces.empty()) // no faces, update can not work correctly
-        return false;
-      // if there is no edges indexes, any face can be used: take the first
       boost::shared_ptr<Model_Data> aData = 
         boost::dynamic_pointer_cast<Model_Data>(owner()->data());
       TDF_Label aLab = aData->label();
+      // getting a type of selected shape
+      Handle(TDataStd_Integer) aTypeAttr;
+      if (!aLab.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr)) {
+        return false;
+      }
+      TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum)(aTypeAttr->Get());
+      // selected indexes will be needed in each "if"
       Handle(TDataStd_IntPackedMap) aSubIds;
       boost::shared_ptr<GeomAPI_Shape> aNewSelected;
-      if (!aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0) {
-        aNewSelected = *(aFaces.begin());
-      } else { // searching for most looks-like initial face by the indexes
-        // prepare edges of the current resut for the fast searching
-        TColStd_MapOfTransient allCurves;
-        FeaturePtr aContextFeature = owner()->document()->feature(aContext);
-        CompositeFeaturePtr aComposite = 
-          boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
-        if (!aComposite) // must be composite at least for the current implementation
+      bool aNoIndexes = 
+        !aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
+      // for now working only with composite features
+      FeaturePtr aContextFeature = owner()->document()->feature(aContext);
+      CompositeFeaturePtr aComposite = 
+        boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+      if (!aComposite || aComposite->numberOfSubs() == 0) {
+        return false;
+      }
+
+      if (aShapeType == TopAbs_FACE) {
+        // If this is a wire with plane defined thin it is a sketch-like object
+        std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+        GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+          aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
+        if (aFaces.empty()) // no faces, update can not work correctly
           return false;
-        const int aSubNum = aComposite->numberOfSubs();
-        for(int a = 0; a < aSubNum; a++) {
-          if (aSubIds->Contains(aComposite->subFeatureId(a))) {
-            FeaturePtr aSub = aComposite->subFeature(a);
-            const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
-            std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
-            for(; aRes != aResults.cend(); aRes++) {
-              ResultConstructionPtr aConstr = 
-                boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
-              if (aConstr->shape() && aConstr->shape()->isEdge()) {
-                const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
-                TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
-                if (!anEdge.IsNull()) {
-                  Standard_Real aFirst, aLast;
-                  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
-                  allCurves.Add(aCurve);
+        // if there is no edges indexes, any face can be used: take the first
+        boost::shared_ptr<GeomAPI_Shape> aNewSelected;
+        if (aNoIndexes) {
+          aNewSelected = *(aFaces.begin());
+        } else { // searching for most looks-like initial face by the indexes
+          // prepare edges of the current resut for the fast searching
+          TColStd_MapOfTransient allCurves;
+          const int aSubNum = aComposite->numberOfSubs();
+          for(int a = 0; a < aSubNum; a++) {
+            if (aSubIds->Contains(aComposite->subFeatureId(a))) {
+              FeaturePtr aSub = aComposite->subFeature(a);
+              const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+              std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes;
+              for(aRes = aResults.cbegin(); aRes != aResults.cend(); aRes++) {
+                ResultConstructionPtr aConstr = 
+                  boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+                if (aConstr->shape() && aConstr->shape()->isEdge()) {
+                  const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+                  TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+                  if (!anEdge.IsNull()) {
+                    Standard_Real aFirst, aLast;
+                    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+                    allCurves.Add(aCurve);
+                  }
+                }
+              }
+            }
+          }
+          // iterate new result faces and searching for these edges
+          std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
+          double aBestFound = 0; // best percentage of found edges
+          for(; aFacesIter != aFaces.end(); aFacesIter++) {
+            int aFound = 0, aNotFound = 0;
+            TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
+            for(; anEdgesExp.More(); anEdgesExp.Next()) {
+              TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
+              if (!anEdge.IsNull()) {
+                Standard_Real aFirst, aLast;
+                Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+                if (allCurves.Contains(aCurve)) {
+                  aFound++;
+                } else {
+                  aNotFound++;
                 }
               }
             }
+            if (aFound + aNotFound != 0) {
+              double aPercentage = double(aFound) / double(aFound + aNotFound);
+              if (aPercentage > aBestFound) {
+                aBestFound = aPercentage;
+                aNewSelected = *aFacesIter;
+              }
+            }
           }
         }
-        // iterate new result faces and searching for these edges
-        std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
-        double aBestFound = 0; // best percentage of found edges
-        for(; aFacesIter != aFaces.end(); aFacesIter++) {
-          int aFound = 0, aNotFound = 0;
-          TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
-          for(; anEdgesExp.More(); anEdgesExp.Next()) {
-            TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
-            if (!anEdge.IsNull()) {
-              Standard_Real aFirst, aLast;
-              Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
-              if (allCurves.Contains(aCurve)) {
-                aFound++;
-              } else {
-                aNotFound++;
+        if (aNewSelected) { // store this new selection
+          selectConstruction(aContext, aNewSelected);
+          owner()->data()->sendAttributeUpdated(this);
+          return true;
+        }
+      } else if (aShapeType == TopAbs_EDGE) {
+        // just reselect the edge by the id
+        const int aSubNum = aComposite->numberOfSubs();
+        for(int a = 0; a < aSubNum; a++) {
+          // if aSubIds take any, the first appropriate
+          if (aSubIds->IsEmpty() || aSubIds->Contains(aComposite->subFeatureId(a))) {
+            // found the appropriate feature
+            FeaturePtr aFeature = aComposite->subFeature(a);
+            std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
+              aFeature->results().cbegin();
+            for(;aResIter != aFeature->results().cend(); aResIter++) {
+              ResultConstructionPtr aRes = 
+                boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
+              if (aRes && aRes->shape() && aRes->shape()->isEdge()) { // found!
+                selectConstruction(aContext, aRes->shape());
+                owner()->data()->sendAttributeUpdated(this);
+                return true;
               }
             }
           }
-          if (aFound + aNotFound != 0) {
-            double aPercentage = double(aFound) / double(aFound + aNotFound);
-            if (aPercentage > aBestFound) {
-              aBestFound = aPercentage;
-              aNewSelected = *aFacesIter;
+        }
+      } else if (aShapeType == TopAbs_VERTEX) {
+        // just reselect the vertex by the id of edge
+        const int aSubNum = aComposite->numberOfSubs();
+        for(int a = 0; a < aSubNum; a++) {
+          // if aSubIds take any, the first appropriate
+          int aFeatureID = aComposite->subFeatureId(a);
+          if (aSubIds->IsEmpty() || aSubIds->Contains(aFeatureID)) {
+            // searching for deltas
+            int aVertexNum = 0;
+            if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 1;
+            else if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 2;
+            // found the feature with appropriate edge
+            FeaturePtr aFeature = aComposite->subFeature(a);
+            std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
+              aFeature->results().cbegin();
+            for(;aResIter != aFeature->results().cend(); aResIter++) {
+              ResultConstructionPtr aRes = 
+                boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
+              if (aRes && aRes->shape()) {
+                if (aRes->shape()->isVertex() && aVertexNum == 0) { // found!
+                  selectConstruction(aContext, aRes->shape());
+                  owner()->data()->sendAttributeUpdated(this);
+                  return true;
+                } else if (aRes->shape()->isEdge() && aVertexNum > 0) {
+                  const TopoDS_Shape& anEdge = aRes->shape()->impl<TopoDS_Shape>();
+                  int aVIndex = 1;
+                  for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
+                    if (aVIndex == aVertexNum) { // found!
+                      boost::shared_ptr<GeomAPI_Shape> aVertex(new GeomAPI_Shape);
+                      aVertex->setImpl(new TopoDS_Shape(aVExp.Current()));
+                      selectConstruction(aContext, aVertex);
+                      owner()->data()->sendAttributeUpdated(this);
+                      return true;
+                    }
+                    aVIndex++;
+                  }
+                }
+              }
             }
           }
         }
       }
-      if (aNewSelected) { // store this new selection
-        selectConstruction(aContext, aNewSelected);
-        return true;
-      }
     }
   }
   return false; // unknown case
@@ -215,12 +307,20 @@ void Model_AttributeSelection::selectConstruction(
   TDF_Label aLab = aData->label();
   // identify the reuslts of sub-object of the composite by edges
   const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+  // save type of the selected shape in integer attribute
+  TopAbs_ShapeEnum aShapeType = aSubShape.ShapeType();
+  TDataStd_Integer::Set(aLab, (int)aShapeType);
+  gp_Pnt aVertexPos;
   TColStd_MapOfTransient allCurves;
-  for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
-    TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
-    Standard_Real aFirst, aLast;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
-    allCurves.Add(aCurve);
+  if (aShapeType == TopAbs_VERTEX) { // compare positions
+    aVertexPos = BRep_Tool::Pnt(TopoDS::Vertex(aSubShape));
+  } else { 
+    for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
+      TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
+      Standard_Real aFirst, aLast;
+      Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+      allCurves.Add(aCurve);
+    }
   }
   // iterate and store the result ids of sub-elements
   Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
@@ -233,17 +333,40 @@ void Model_AttributeSelection::selectConstruction(
     for(; aRes != aResults.cend(); aRes++) {
       ResultConstructionPtr aConstr = 
         boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
-      if (aConstr->shape() && aConstr->shape()->isEdge()) {
-        const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
-        TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
-        if (!anEdge.IsNull()) {
-          Standard_Real aFirst, aLast;
-          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
-          if (allCurves.Contains(aCurve)) {
-            boost::shared_ptr<Model_Data> aSubData = boost::dynamic_pointer_cast<Model_Data>(aSub->data());
-            TDF_Label aSubLab = aSubData->label();
+      if (!aConstr->shape()) {
+        continue;
+      }
+      if (aShapeType == TopAbs_VERTEX) {
+        if (aConstr->shape()->isVertex()) { // compare vertices positions
+          const TopoDS_Shape& aVertex = aConstr->shape()->impl<TopoDS_Shape>();
+          gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
+          if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
             aRefs->Add(aComposite->subFeatureId(a));
           }
+        } else { // get first or last vertex of the edge: last is stored with negative sign
+          const TopoDS_Shape& anEdge = aConstr->shape()->impl<TopoDS_Shape>();
+          int aDelta = kSTART_VERTEX_DELTA;
+          for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
+            gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVExp.Current()));
+            if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
+              aRefs->Add(aComposite->subFeatureId(a));
+              aRefs->Add(aDelta + aComposite->subFeatureId(a));
+              break;
+            }
+            aDelta += kSTART_VERTEX_DELTA;
+          }
+        }
+      } else {
+        if (aConstr->shape()->isEdge()) {
+          const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+          TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+          if (!anEdge.IsNull()) {
+            Standard_Real aFirst, aLast;
+            Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+            if (allCurves.Contains(aCurve)) {
+              aRefs->Add(aComposite->subFeatureId(a));
+            }
+          }
         }
       }
     }
index cb7158b75de28390da8316551c2dd3bfcfc26e1a..f23e684ca782ebc904478691fb9b383ab4eb1b95 100644 (file)
@@ -152,13 +152,14 @@ class Model_Data : public ModelAPI_Data
   /// Returns the identifier of feature-owner, unique in this document
   MODEL_EXPORT virtual int featureId() const;
 
+  // returns all objects referenced to this
+  MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+
 private:
   // removes all information about back references
   void eraseBackReferences();
   // adds a back reference (with identifier which attribute references to this object
   void addBackReference(FeaturePtr theFeature, std::string theAttrID);
-  // returns all objects referenced to this
-  const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
   // returns all references by attributes of this data
   // \param the returned list of pairs: id of referenced attribute and list of referenced objects
   void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
index cb05a7fbbf59b7af19f8125c262da3210faeafd9..2487b7c30f1b6d0b068a65299380202a0a5fa73b 100644 (file)
@@ -10,6 +10,7 @@
 #include <Model_ResultPart.h>
 #include <Model_ResultConstruction.h>
 #include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
 #include <ModelAPI_Validator.h>
 #include <Events_Loop.h>
 #include <Events_Error.h>
@@ -210,12 +211,12 @@ void Model_Document::close()
   for (; aSubIter != mySubs.end(); aSubIter++)
     subDoc(*aSubIter)->close();
   mySubs.clear();
-  // close this
-  /* do not close because it can be undoed
-   if (myDoc->CanClose() == CDM_CCS_OK)
-   myDoc->Close();
-   Model_Application::getApplication()->deleteDocument(myID);
-   */
+  // close this only if it is module document, otherwise it can be undoed
+  if (this == aPM->moduleDocument().get()) {
+    if (myDoc->CanClose() == CDM_CCS_OK)
+      myDoc->Close();
+    Model_Application::getApplication()->deleteDocument(myID);
+  }
 }
 
 void Model_Document::startOperation()
@@ -702,29 +703,30 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
   TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
   for (; aLabIter.More(); aLabIter.Next()) {
     TDF_Label aFeatureLabel = aLabIter.Value()->Label();
+    FeaturePtr aFeature;
     if (!myObjs.IsBound(aFeatureLabel)) {  // a new feature is inserted
       // create a feature
-      FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature(
+      aFeature = ModelAPI_Session::get()->createFeature(
           TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
               .ToCString());
-      if (!aNewObj) {  // somethig is wrong, most probably, the opened document has invalid structure
+      if (!aFeature) {  // somethig is wrong, most probably, the opened document has invalid structure
         Events_Error::send("Invalid type of object in the document");
         aLabIter.Value()->Label().ForgetAllAttributes();
         continue;
       }
       // this must be before "setData" to redo the sketch line correctly
-      myObjs.Bind(aFeatureLabel, aNewObj);
-      aNewFeatures.insert(aNewObj);
-      initData(aNewObj, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
+      myObjs.Bind(aFeatureLabel, aFeature);
+      aNewFeatures.insert(aFeature);
+      initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
 
       // event: model is updated
       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-      ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent);
+      ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
 
       // update results of the appeared feature
-      updateResults(aNewObj);
+      updateResults(aFeature);
     } else {  // nothing is changed, both iterators are incremented
-      FeaturePtr aFeature = myObjs.Find(aFeatureLabel);
+      aFeature = myObjs.Find(aFeatureLabel);
       aKeptFeatures.insert(aFeature);
       if (theMarkUpdated) {
         static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
@@ -733,11 +735,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
       updateResults(aFeature);
     }
   }
-  // execute new features to restore results: after features creation to make all references valid
-  /*std::set<FeaturePtr>::iterator aNewIter = aNewFeatures.begin();
-   for(; aNewIter != aNewFeatures.end(); aNewIter++) {
-   (*aNewIter)->execute();
-   }*/
   // check all features are checked: if not => it was removed
   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myObjs);
   while (aFIter.More()) {
@@ -752,14 +749,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
       static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
-      /*
-      for (; aRIter != aResults.cend(); aRIter++) {
-        boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
-        //aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
-        ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
-        ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName());
-      }
-      */
       // redisplay also removed feature (used for sketch and AISObject)
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
       aFeature->erase();
@@ -924,6 +913,23 @@ boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
   return aResult;
 }
 
+boost::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
+    const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
+  ObjectPtr anOldObject = object(aLab);
+  boost::shared_ptr<ModelAPI_ResultGroup> aResult;
+  if (anOldObject) {
+    aResult = boost::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
+  }
+  if (!aResult) {
+    aResult = boost::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
+    storeResult(theFeatureData, aResult, theIndex);
+  }
+  return aResult;
+}
+
 boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
     const boost::shared_ptr<ModelAPI_Result>& theResult)
 {
@@ -969,7 +975,8 @@ void Model_Document::updateResults(FeaturePtr theFeature)
           aNewBody = createBody(theFeature->data(), aResIndex);
         } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
           aNewBody = createPart(theFeature->data(), aResIndex);
-        } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str()) {
+        } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str() &&
+          aGroup->Get() != ModelAPI_ResultGroup::group().c_str()) {
           Events_Error::send(std::string("Unknown type of result is found in the document:") +
             TCollection_AsciiString(aGroup->Get()).ToCString());
         }
index cbea4a19e58826dd8c9148f0e33679ccea3b60d8..d8743f0994d03ffe707df3d26605251531c81f6f 100644 (file)
@@ -121,6 +121,9 @@ class Model_Document : public ModelAPI_Document
   /// Creates a part results
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+  /// Creates a group results
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+      const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
 
   //! Returns a feature by result (owner of result)
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
index ce342c2e99a07a647388c2d6099a8079b6a75edb..3c7f7a689cd018483b88d64fbb0ebc1cc7e5dea8 100644 (file)
@@ -101,16 +101,12 @@ boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
   return boost::shared_ptr<GeomAPI_Shape>();
 }
 
-boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
-{
-  return myOwner;
-}
-
 void Model_ResultBody::clean()
 {
   std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
   for(; aBuilder != myBuilders.end(); aBuilder++)
     delete *aBuilder;
+  myBuilders.clear();
 }
 
 Model_ResultBody::~Model_ResultBody()
index 340b35bb515e9699b244f69d22680eb7acd2cebe..a12ccb87d509deee934bdffbd5c30c1e27237153 100644 (file)
@@ -23,7 +23,6 @@ class TNaming_Builder;
  */
 class Model_ResultBody : public ModelAPI_ResultBody
 {
-  boost::shared_ptr<ModelAPI_Feature> myOwner;  ///< owner of this result
   /// builders that tores the naming history: one per label to allow store several shapes to one 
   /// label; index in vector corresponds to the label tag
   std::vector<TNaming_Builder*> myBuilders;
@@ -41,8 +40,6 @@ public:
 
   /// Returns the shape-result produced by this feature
   MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
-  /// Returns the source feature of this result
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
 
   /// Records the subshape newShape which was generated during a topological construction.
   /// As an example, consider the case of a face generated in construction of a box.
diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp
new file mode 100644 (file)
index 0000000..2fd1ead
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        Model_ResultGroup.cpp
+// Created:     08 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Model_ResultGroup.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+Model_ResultGroup::Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData)
+{
+  setIsConcealed(false);
+  myOwnerData = theOwnerData;
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape() const
+{
+  boost::shared_ptr<GeomAPI_Shape> aResult;
+  if (myOwnerData) {
+    AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
+    if (aList) {
+      std::list<boost::shared_ptr<GeomAPI_Shape> > aSubs;
+      for(int a = aList->size(); a >= 0; a--) {
+        boost::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
+        if (aSelection && !aSelection->isNull()) {
+          aSubs.push_back(aSelection);
+        }
+      }
+      if (!aSubs.empty()) {
+        aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
+      }
+    }
+  }
+  return aResult;
+}
diff --git a/src/Model/Model_ResultGroup.h b/src/Model/Model_ResultGroup.h
new file mode 100644 (file)
index 0000000..30e3588
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        Model_ResultGroup.h
+// Created:     08 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_ResultGroup_H_
+#define Model_ResultGroup_H_
+
+#include "Model.h"
+#include <ModelAPI_ResultGroup.h>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class Model_ResultGroup : public ModelAPI_ResultGroup
+{
+  boost::shared_ptr<ModelAPI_Data> myOwnerData;  ///< data of owner of this result
+public:
+  /// Returns the compound of selected entities
+  MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape() const;
+
+  /// Removes the stored builders
+  MODEL_EXPORT virtual ~Model_ResultGroup() {}
+
+protected:
+  /// Makes a body on the given feature data
+  Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData);
+
+  friend class Model_Document;
+};
+
+#endif
index 0bfa08a58c57ad2e1486feafaa3df577f0cb887a..bbc99cbb1543d004c3504af482afb9439aa07577 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultPart.h
     ModelAPI_ResultParameters.h
+    ModelAPI_ResultGroup.h
     ModelAPI_ResultValidator.h
     ModelAPI_AttributeValidator.h
     ModelAPI_Tools.h
index 2acf4fc6bf2cc264c2123d1c2094aa2f11119c6a..191345f1a7313c9359c7f17b4907d852a2dbff43 100644 (file)
@@ -8,6 +8,7 @@
 #include "ModelAPI.h"
 #include <string>
 #include <list>
+#include <set>
 #include <boost/shared_ptr.hpp>
 
 class ModelAPI_AttributeDocRef;
@@ -109,6 +110,9 @@ class MODELAPI_EXPORT ModelAPI_Data
   /// Returns the identifier of feature-owner, unique in this document
   virtual int featureId() const = 0;
 
+ // returns all objects referenced to this
+  virtual const std::set<boost::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
+
  protected:
   /// Objects are created for features automatically
   ModelAPI_Data()
index cdfa1d75ed89bb6661e2d7e30a239cfc3eab1a88..703ab0f881cebeb997bbf62d9fe3b5d4747ec1f8 100644 (file)
@@ -17,6 +17,7 @@ class ModelAPI_Result;
 class ModelAPI_ResultConstruction;
 class ModelAPI_ResultBody;
 class ModelAPI_ResultPart;
+class ModelAPI_ResultGroup;
 class ModelAPI_Data;
 
 /**\class Model_Document
@@ -76,6 +77,9 @@ public:
   /// Creates a part results
   virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  /// Creates a group results
+  virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+      const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
 
   //! Returns a feature by result (owner of result)
   virtual boost::shared_ptr<ModelAPI_Feature> feature(
diff --git a/src/ModelAPI/ModelAPI_ResultGroup.h b/src/ModelAPI/ModelAPI_ResultGroup.h
new file mode 100644 (file)
index 0000000..a8b183c
--- /dev/null
@@ -0,0 +1,42 @@
+// File:        ModelAPI_ResultGroup.hxx
+// Created:     07 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultGroup_H_
+#define ModelAPI_ResultGroup_H_
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class ModelAPI_ResultGroup : public ModelAPI_Result
+{
+public:
+  /// Returns the group identifier of this result
+  virtual std::string groupName()
+  {
+    return group();
+  }
+
+  /// Returns the group identifier of this result
+  static std::string group()
+  {
+    static std::string MY_GROUP = "Groups";
+    return MY_GROUP;
+  }
+
+  /// Returns the compound of selected entities
+  virtual boost::shared_ptr<GeomAPI_Shape> shape() const = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultGroup> ResultGroupPtr;
+
+#endif
index cd728aa7adcb2711218549b172b0062bd6b83df1..a28d62d88e7dcc089b03b95b41beaf2412c84254 100644 (file)
@@ -29,6 +29,9 @@
 
 #include <Events_Loop.h>
 
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+
 #ifdef _DEBUG
 #include <QDebug>
 #endif
@@ -249,6 +252,7 @@ bool ModuleBase_Operation::activateByPreselection()
   ModuleBase_ViewerPrs aPrs;
   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
   QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+  bool isSet = false;
   for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
        (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
        ++aWIt, ++aPIt) {
@@ -256,10 +260,16 @@ bool ModuleBase_Operation::activateByPreselection()
     aPrs = (*aPIt);
     ModuleBase_WidgetValueFeature aValue;
     aValue.setObject(aPrs.object());
-    if (!aWgt->setValue(&aValue))
+    // Check if the selection has a selected point
+    // for today it is impossible to do because
+    // the selected point demands convertation to Sketch plane 2d
+    if (!aWgt->setValue(&aValue)) {
+      isSet = false;
       break;
+    } else 
+      isSet = true;
   }
-  if (canBeCommitted()) {
+  if (isSet && canBeCommitted()) {
     // if all widgets are filled with selection
     commit();
     return true;
index 267cb064740a4958beddfe3dc732bd7836e29f4c..8593ab6323e07099cf5e6d28a38c913b9f84776d 100644 (file)
@@ -65,6 +65,7 @@ bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStr
 
 bool NewGeom_DataModel::close()
 {
+  myModule->workshop()->closeDocument();
   return LightApp_DataModel::close();
 }
 
index d9ce85febf901d738fa94427301ce74ddd4c10ca..fe9cd2310214d6a07099bc0564055e564f2b992d 100644 (file)
@@ -48,6 +48,9 @@ void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
       return;
     else {
       mySelector->viewer()->getViewManager()->disconnect(this);
+      OCCViewer_Viewer* aViewer = mySelector->viewer();
+      if (aViewer)
+        aViewer->disconnect(this);
     }
   }
   mySelector = theSel;
@@ -123,6 +126,11 @@ void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
 {
   mySelector->viewer()->enableSelection(isEnabled);
+  // there is a fix for a black-colored window 
+  // the viewer rubber band is valid if the values delta is less than 1
+  // TODO: remove this row after moving to SALOME 7.5
+  mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
+                                                      : SUIT_ViewModel::KEY_FREE);
 }
 
 //**********************************************
index 035444ba936e51e465f3133a1d3495e6ebed6b57..501105c4f3f80bf395249116e47a3fcbe3db6253 100644 (file)
@@ -186,6 +186,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
           aDisplayer->activate(*anIt, aModes);
         }
         aDisplayer->activate(aFeature, aModes);
+        aDisplayer->clearSelected();
       }
     }
   }// else {
@@ -217,24 +218,6 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
     dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
   if (aPreviewOp) {
     ModuleBase_ISelection* aSelection = workshop()->selection();
-    // Initialise operation with preliminary selection
-    //QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    //QList<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    //QList<ObjectPtr> aObjList;
-    //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-    //if (aHasShift) {
-    //  foreach(ModuleBase_ViewerPrs aPrs, aSelected)
-    //    aObjList.append(aPrs.object());
-
-    //  foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
-    //    if (!aObjList.contains(aPrs.object()))
-    //      aObjList.append(aPrs.object());
-    //  }
-    //} else {
-    //  foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
-    //    aObjList.append(aPrs.object());
-    //}
-    //onSetSelection(aObjList);
     aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
   }
 }
@@ -312,16 +295,16 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject
     ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
     aSketchOp->initSelection(aSelection, myWorkshop->viewer());
-  } //else if (aFeature) {
-    //anOperation->setFeature(aFeature);
+  } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
+    anOperation->setFeature(aFeature);
     ////Deactivate result of current feature in order to avoid its selection
-    //XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
-    //std::list<ResultPtr> aResults = aFeature->results();
-    //std::list<ResultPtr>::const_iterator aIt;
-    //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-    //  aDisplayer->deactivate(*aIt);
-    //}
-  //}
+    XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+    std::list<ResultPtr> aResults = aFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+      aDisplayer->deactivate(*aIt);
+    }
+  }
   sendOperation(anOperation);
   xWorkshop()->actionsMgr()->updateCheckState();
 }
index a9d85bb8c194c18af1a0b9c15ae47bd6b77abf21..517c77caed72dfd7f0370bdad25eb3279b4db1fb 100644 (file)
@@ -249,7 +249,7 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_
     // the feature is moved only if there is no a local selection on this feature
     if (!isMoved) {
       // MPV: added condition because it could be external edge of some object, not sketch
-      if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
+      if (aSketchFeature && sketch()->isSub(aSketchFeature)) {
         aSketchFeature->move(aDeltaX, aDeltaY);
         static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
         ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
index 916a31a71f2a4e958e3ddbf706eb0ce35df99548..668cb4653b28ced6903969b4fda8b250d0279b7f 100644 (file)
@@ -412,7 +412,14 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the
       anEdge->setImpl(new TopoDS_Shape(aShape));
 
       anAttr->setValue(aRes, anEdge);
+
       aMyFeature->execute();
+
+      // fix this edge
+      FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+      aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+        setObject(aMyFeature->lastResult());
+
       return aMyFeature->lastResult();
     }
   }
index b5e48183f54196eb8989e053d5839d45f2f7dacd..f327aa7f2ed382c0598aa1e162910ca42a334fa1 100644 (file)
 class PartSetPlugin_Duplicate : public PartSetPlugin_Part
 {
  public:
+    /// Duplicate kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_DUPLICATE_KIND("Duplicate");
+    return MY_DUPLICATE_KIND;
+  }
+
   /// the reference to copy: reference to the attribute
   inline static const std::string& ORIGIN_REF()
   {
index 0ad4b8b928ad69e4ec78822999fedf0fa66e1e3c..31c80e4953a769853494e17e785805c59b6b3a7e 100644 (file)
@@ -21,10 +21,10 @@ FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
   if (theFeatureID == PartSetPlugin_Part::ID()) {
     return FeaturePtr(new PartSetPlugin_Part);
   }
-  if (theFeatureID == "duplicate") {
+  if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
     return FeaturePtr(new PartSetPlugin_Duplicate);
   }
-  if (theFeatureID == "remove") {
+  if (theFeatureID == PartSetPlugin_Remove::ID()) {
     return FeaturePtr(new PartSetPlugin_Remove);
   }
   // feature of such kind is not found
index 8a9c5ec613e0dc5c5827f728c508554322f46fc3..4a846cc42a98088901b5d05ae21d98a8f31b1b77 100644 (file)
@@ -2,8 +2,8 @@
   <workbench id="Part">
     <group id="Operations">
       <feature id="Part" title="New part" tooltip="Create a new part" icon=":pictures/part_ico.png"/>
-      <feature id="duplicate" title="Duplicate" tooltip="Duplicate selected part" icon=":icons/duplicate.png"/>
-      <feature id="remove" title="Remove part"  tooltip="Remove active part" icon=":icons/remove.png"/>
+      <feature id="Duplicate" title="Duplicate" tooltip="Duplicate selected part" icon=":icons/duplicate.png"/>
+      <feature id="Remove" title="Remove part"  tooltip="Remove active part" icon=":icons/remove.png"/>
     </group>
   </workbench>
 </plugin>
index d9afa4fa9d9a619a485c962c85106e53b2e23a72..b2615a6bbc98d8b220215fa306b4f9f9d9f7f27d 100644 (file)
@@ -37,68 +37,100 @@ void SketchPlugin_Arc::initAttributes()
 void SketchPlugin_Arc::execute()
 {
   SketchPlugin_Sketch* aSketch = sketch();
-  if (aSketch) {
-    std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
-
+  // result for the arc is set only when all obligatory attributes are initialized,
+  // otherwise AIS object is used to visualize the arc's preview
+  if (aSketch && isFeatureValid()) {
     // compute a circle point in 3D view
     boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
         GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
     // compute the arc start point
     boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
         GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
-    if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) {
-      boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
-      // make a visible point
-      boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
-      //aShapes.push_back(aCenterPointShape);
-      boost::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
-          data(), 0);
-      aConstr1->setShape(aCenterPointShape);
-      aConstr1->setIsInHistory(false);
-      setResult(aConstr1, 0);
-
-      // make a visible circle
-      boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
-          aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-      bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
-      if (aHasPlane) {
-        boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
-        boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
-
-        // compute and change the arc end point
-        boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
-            GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
-        if (anEndAttr->isInitialized()) {
-          boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
-              new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
-          boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
-          if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
-            anEndAttr->setValue(aProjection);
-        }
-        boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
-
-        boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
-            aCenter, aStartPoint, aEndPoint, aNormal);
-        if (aCircleShape) {
-          boost::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
-              data(), 1);
-          aConstr2->setShape(aCircleShape);
-          aConstr2->setIsInHistory(false);
-          setResult(aConstr2, 1);
-          //aShapes.push_back(aCircleShape);
+
+    boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+    // make a visible point
+    boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+    boost::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
+        data(), 0);
+    aConstr1->setShape(aCenterPointShape);
+    aConstr1->setIsInHistory(false);
+    setResult(aConstr1, 0);
+
+    // make a visible circle
+    boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+    bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+    if (aHasPlane) {
+      boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+      boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+
+      // compute and change the arc end point
+      boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
+          GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+      boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
+          new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
+      boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
+      if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
+        anEndAttr->setValue(aProjection);
+      boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+
+      boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
+          aCenter, aStartPoint, aEndPoint, aNormal);
+      if (aCircleShape) {
+        boost::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
+            data(), 1);
+        aConstr2->setShape(aCircleShape);
+        aConstr2->setIsInHistory(false);
+        setResult(aConstr2, 1);
+      }
+    }
+  }
+}
+
+AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
+{
+  SketchPlugin_Sketch* aSketch = sketch();
+  if (aSketch) {
+    // if the feature is valid, the execute() method should be performed, AIS object is empty
+    if (!isFeatureValid()) {
+      std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+
+      // compute a circle point in 3D view
+      boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
+          GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+      if (aCenterAttr->isInitialized()) {
+        boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+        // make a visible point
+        boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+        aShapes.push_back(aCenterPointShape);
+
+        boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
+            GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
+        if (aStartAttr->isInitialized()) {
+          // make a visible circle
+          boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+              aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+          bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+          if (aHasPlane) {
+            boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+            boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+            boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
+                                                            aCenter, aStartPoint, aStartPoint, aNormal);
+            if (aCircleShape) {
+              aShapes.push_back(aCircleShape);
+            }
+          }
         }
       }
-      /*
-       boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
-       // store the result
-       boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = 
-       document()->createConstruction(data());
-       aConstr->setShape(aCompound);
-       aConstr->setIsInHistory(false);
-       setResult(aConstr);
-       */
+      boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+      AISObjectPtr anAIS = thePrevious;
+      if (!anAIS)
+        anAIS = AISObjectPtr(new GeomAPI_AISObject);
+      anAIS->createShape(aCompound);
+      return anAIS;
     }
   }
+  return AISObjectPtr();
 }
 
 void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
@@ -147,3 +179,15 @@ double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>&
 bool SketchPlugin_Arc::isFixed() {
   return data()->selection(EXTERNAL_ID())->context();
 }
+
+bool SketchPlugin_Arc::isFeatureValid()
+{
+  boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+  boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
+  boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+
+  return aCenterAttr->isInitialized() && aStartAttr->isInitialized() && anEndAttr->isInitialized();
+}
index 3ee2ba8e714c0bfa2a271d89fea9ae1eb104d114..a60774336e9f58d10779852101129d699f4e1a63 100644 (file)
 /**\class SketchPlugin_Arc
  * \ingroup DataModel
  * \brief Feature for creation of the new arc of circle in PartSet.
+ * The visualization of this object is separated in two parts. The first one is an AIS object
+ * calculated when there is non-initialized attributes of the arc. The second is a result and
+ * it is calculated if all attributes are initialized.
  */
-class SketchPlugin_Arc : public SketchPlugin_Feature  //, public GeomAPI_IPresentable
+class SketchPlugin_Arc : public SketchPlugin_Feature, public GeomAPI_IPresentable
 {
  public:
   /// Arc feature kind
@@ -60,10 +63,7 @@ class SketchPlugin_Arc : public SketchPlugin_Feature  //, public GeomAPI_IPresen
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
   /// Returns the AIS preview
-  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
-  {
-    return simpleAISObject(firstResult(), thePrevious);
-  }
+  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
@@ -76,6 +76,10 @@ class SketchPlugin_Arc : public SketchPlugin_Feature  //, public GeomAPI_IPresen
 
   /// Use plugin manager for features creation
   SketchPlugin_Arc();
+
+private:
+  /// Returns true if all obligatory attributes are initialized
+  bool isFeatureValid();
 };
 
 #endif
index c9763327e2b6f23f97452473eef478a45c902b2a..1b02335dffd69fe730f98ee3c8f62e476ecfb920 100644 (file)
@@ -6,6 +6,9 @@
 
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
 SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
 {
 }
@@ -27,16 +30,27 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious
   boost::shared_ptr<ModelAPI_Data> aData = data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  if (!anAttr || !anAttr->isObject())
-    return thePrevious;
-
-  boost::shared_ptr<ModelAPI_ResultConstruction> aConst = 
-    boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
-  if (!aConst) 
+  if (!anAttr /*|| !anAttr->isObject()*/)
     return thePrevious;
 
   boost::shared_ptr<GeomAPI_Shape> aShape;
-  aShape = aConst->shape();
+
+  if (anAttr->isObject()) {
+    boost::shared_ptr<ModelAPI_ResultConstruction> aConst;
+    aConst = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+
+    if (!aConst) 
+      return thePrevious;
+    aShape = aConst->shape();
+  }
+  else {
+    boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+                             boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+    if (!aPointAttr)
+      return thePrevious;
+    boost::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
+    aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
+  }
 
   AISObjectPtr anAIS = thePrevious;
   if (!anAIS)
index da25c09994581e44f9153dc447b05979ad525c63..2d46d8ca14e2bb79a1c3a29564ba528bd59b1edb 100644 (file)
@@ -11,31 +11,23 @@ SketchPlugin_Feature::SketchPlugin_Feature()
   mySketch = 0;
 }
 
-/*
 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
 {
   if (!mySketch) {
     // find sketch that references to this feature
-    int aSketches = document()->size(ModelAPI_Feature::group());
-    for (int a = 0; a < aSketches && !mySketch; a++) {
-      ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+    const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
+    std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
+    for(; aBackRef != aBackRefs.end(); aBackRef++) {
       boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
-        boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
+        boost::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
       if (aSketch) {
-        std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
-            ->list();
-        std::list<ObjectPtr>::iterator aSub = aList.begin();
-        for (; aSub != aList.end(); aSub++) {
-          if ((*aSub)->data()->isEqual(data())) {
-            mySketch = aSketch.get();
-            break;
-          }
-        }
+        mySketch = aSketch.get();
+        break;
       }
     }
   }
   return mySketch;
-}*/
+}
 
 AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
                                                    AISObjectPtr thePrevious)
index 97a2d423bd605102a579461c1774ac305baff60e..8c022ed2bc441993c8076809bc1c28ce2463c86d 100644 (file)
@@ -56,7 +56,7 @@ class SketchPlugin_Feature : public ModelAPI_Feature
   SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
 
   /// Returns the sketch of this feature
-  inline SketchPlugin_Sketch* sketch() {return mySketch;}
+  SketchPlugin_Sketch* sketch();
 protected:
   /// Sets the higher-level feature for the sub-feature (sketch for line)
   void setSketch(SketchPlugin_Sketch* theSketch)
index 75c404a772a12922e9bd6284a8b07e4d3a952d15..2d85a43b3873b99f1d938c29296da7230f0572c0 100644 (file)
@@ -21,8 +21,7 @@ using namespace std;
 
 SketchPlugin_Line::SketchPlugin_Line()
     : SketchPlugin_Feature()
-{
-}
+{}
 
 void SketchPlugin_Line::initAttributes()
 {
index 42b70c4c692a41d008b8ba8524318b711ca03c49..b5f101595aa27b8786bd6391b71bb4964ace0b25 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Feature.h>
 
 #include <boost/smart_ptr/shared_ptr.hpp>
 
+#include <math.h>
 #include <vector>
 
 using namespace std;
@@ -41,6 +46,10 @@ void SketchPlugin_Sketch::initAttributes()
   data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type());
   data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type());
   data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type());
+  // the selected face, base for the sketcher plane, not obligatory
+  data()->addAttribute(SketchPlugin_Feature::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(
+    getKind(), SketchPlugin_Feature::EXTERNAL_ID());
 }
 
 void SketchPlugin_Sketch::execute()
@@ -69,6 +78,11 @@ void SketchPlugin_Sketch::execute()
   for (; anIt != aLast; anIt++) {
     aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
     if (aFeature) {
+      // do not include the external edges into the result
+      if (aFeature->data()->attribute(SketchPlugin_Feature::EXTERNAL_ID())) {
+        if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value())
+          continue;
+      }
 
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
@@ -254,3 +268,47 @@ void SketchPlugin_Sketch::erase()
   }
   ModelAPI_CompositeFeature::erase();
 }
+
+void SketchPlugin_Sketch::attributeChanged() {
+  static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
+  boost::shared_ptr<GeomAPI_Shape> aSelection = 
+    data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+  if (aSelection && !myIsUpdated) { // update arguments due to the selection value
+    myIsUpdated = true;
+    // update the sketch plane
+    boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+    if (aPlane) {
+      double anA, aB, aC, aD;
+      aPlane->coefficients(anA, aB, aC, aD);
+
+      // calculate attributes of the sketch
+      boost::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+      boost::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+      boost::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+      aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+      boost::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+      // X axis is preferable to be dirX on the sketch
+      static const double tol = 1.e-7;
+      bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+      boost::shared_ptr<GeomAPI_Dir> aTempDir(
+        isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+      boost::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+      boost::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+      boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+        data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+      anOrigin->setValue(anOrigPnt);
+      boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+      aNormal->setValue(aNormDir);
+      boost::shared_ptr<GeomDataAPI_Dir> aDirX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+      aDirX->setValue(aXDir);
+      boost::shared_ptr<GeomDataAPI_Dir> aDirY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+      aDirY->setValue(aYDir);
+      boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+    }
+    myIsUpdated = false;
+  }
+}
index 637bd34a90e416f289a0f75a3cdfb44dabfb5b9e..6a07b55c9038696881c6c1d43ae52c78804bb9f2 100644 (file)
@@ -135,6 +135,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPr
   /// Returns the point projected into the sketch plane
   boost::shared_ptr<GeomAPI_Pnt2d> to2D(const boost::shared_ptr<GeomAPI_Pnt>& thePnt);
 
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged();
 protected:
   /// Creates a plane and append it to the list
   /// \param theX the X normal value
index 9e212a4fabc9cd972e63e994dd1d87c288cc8685..14deb7083d3773f5f4e14cba643c2e9e284c1ee5 100644 (file)
       </feature>
 
       <feature id="SketchConstraintRigid" title="Fixed" tooltip="Create constraint defining fixed object" icon=":icons/fixed.png">
-        <feature_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
+        <feature_or_attribute_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
           <validator id="SketchPlugin_ResultPoint"/>
           <validator id="SketchPlugin_ResultLine"/>
           <validator id="SketchPlugin_ResultArc"/>
-        </feature_selector>
+        </feature_or_attribute_selector>
       </feature>
     </group>
   </workbench>
index 081ab537f9c7a6ab02e2b24ab4873b78388813f9..0468a39f75bc4ba8c5da482cdb115eefa28d89b1 100644 (file)
@@ -115,9 +115,11 @@ void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& t
 
 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
 {
-  QAction* anAction = myActions[theId];
-  if (anAction && anAction->isCheckable()) {
-    anAction->setChecked(theChecked);
+  if (myActions.contains(theId)) {
+    QAction* anAction = myActions[theId];
+    if (anAction->isCheckable()) {
+      anAction->setChecked(theChecked);
+    }
   }
 }
 
@@ -135,8 +137,7 @@ void XGUI_ActionsMgr::updateByDocumentKind()
     QString aCmdDocKind;
     if(aCmd) {
       aCmdDocKind = aCmd->documentKind();
-    }
-    else {
+    } else {
       QString aId = eachAction->data().toString();
       if (!aId.isEmpty()) {
         aCmdDocKind = aWorkshop->salomeConnector()->documentKind(aId);
@@ -150,9 +151,8 @@ void XGUI_ActionsMgr::updateByDocumentKind()
 
 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
 {
-  QAction* anAction = myActions[theId];
-  if (anAction) {
-    anAction->setEnabled(theEnabled);
+  if (myActions.contains(theId)) {
+    myActions[theId]->setEnabled(theEnabled);
   }
 }
 
index 2744d196d4114b08b7ae71f7ed55397bb2b75454..14a8735b1dcfaec4f4e236cf0c5f189ba3409ae8 100644 (file)
@@ -42,6 +42,7 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
 XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
 {
   clearModelIndexes();
+  clearSubModels();
 }
 
 void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
@@ -80,10 +81,9 @@ void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr<Events_Message
         }
       } else {  // if sub-objects of first level nodes
         XGUI_PartModel* aPartModel = 0;
-        QList<XGUI_PartModel*>::const_iterator aIt;
-        for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
-          if ((*aIt)->hasDocument(aDoc)) {
-            aPartModel = (*aIt);
+        foreach (XGUI_PartModel* aPart, myPartModels) {
+          if (aPart->hasDocument(aDoc)) {
+            aPartModel = aPart;
             break;
           }
         }
@@ -123,10 +123,9 @@ void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr<Events_Message
         }
       } else {
         XGUI_PartModel* aPartModel = 0;
-        QList<XGUI_PartModel*>::const_iterator aIt;
-        for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
-          if ((*aIt)->hasDocument(aDoc)) {
-            aPartModel = (*aIt);
+        foreach (XGUI_PartModel* aPart, myPartModels) {
+          if (aPart->hasDocument(aDoc)) {
+            aPartModel = aPart;
             break;
           }
         }
@@ -361,12 +360,18 @@ QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex)
 
 void XGUI_DocumentDataModel::clearModelIndexes()
 {
-  QList<QModelIndex*>::const_iterator aIt;
-  for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt)
-    delete (*aIt);
+  foreach (QModelIndex* aIndex, myIndexes) 
+    delete aIndex;
   myIndexes.clear();
 }
 
+void XGUI_DocumentDataModel::clearSubModels()
+{
+  foreach (XGUI_PartModel* aPart, myPartModels) 
+    delete aPart;
+  myPartModels.clear();
+}
+
 ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
 {
   if (theIndex.internalId() == PartsFolder)
@@ -570,3 +575,13 @@ QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
   }
   return QModelIndex();
 }
+
+
+void XGUI_DocumentDataModel::clear()
+{
+  clearModelIndexes();
+  clearSubModels();
+  myActivePart = 0;
+  myActivePartIndex = QModelIndex();
+  myModel->setItemsColor(ACTIVE_COLOR);
+}
index c2436082783f1e3851053acd4f01f4c3018a15ac..a7e9fc944cb6c99ecd0e03fb8131fa284aec0065 100644 (file)
@@ -78,6 +78,10 @@ Q_OBJECT
 
   void rebuildDataTree();
 
+  //! Clear internal data
+  void clear();
+
+
  private:
 
   enum
@@ -98,6 +102,9 @@ Q_OBJECT
   //! Deletes all saved pointers on QModelIndex objects.
   void clearModelIndexes();
 
+  //! Deletes all saved pointers on QModelIndex objects.
+  void clearSubModels();
+
   //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
   void removeSubModel(int theModelId);
 
index 4268115fde4477d1bbe52412c4d440a4ca291c04..699d6e518e2dcd9b40810f1d0bd3970f7bd15c33 100644 (file)
@@ -84,6 +84,14 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   }
 }
 
+void XGUI_DataTree::clear() 
+{
+  mySelectedData.clear();
+  XGUI_DocumentDataModel* aModel = dataModel();
+  aModel->clear();
+  reset();
+}
+
 //********************************************************************
 //********************************************************************
 //********************************************************************
@@ -348,3 +356,11 @@ void XGUI_ObjectsBrowser::processEvent(const boost::shared_ptr<Events_Message>&
 { 
   myDocModel->processEvent(theMessage); 
 }
+
+
+//***************************************************
+void XGUI_ObjectsBrowser::clearContent()  
+{ 
+  myObjectsList.clear();
+  myTreeView->clear(); 
+}
index ebcaffe08ef30deee9dfd8b56a8cf1e295f5d7a3..9e7f901d75224c3d9782242cde3c288a30233b1a 100644 (file)
@@ -36,6 +36,9 @@ signals:
   //! Emited on context menu request
   void contextMenuRequested(QContextMenuEvent* theEvent);
 
+public slots:
+  virtual void clear();
+
  protected slots:
   virtual void commitData(QWidget* theEditor);
 
@@ -96,6 +99,9 @@ Q_OBJECT
 
   void processEvent(const boost::shared_ptr<Events_Message>& theMessage);
 
+  // Resets the object browser into initial state
+  void clearContent();
+
 signals:
   //! Emited when selection is changed
   void selectionChanged();
index 4d91ceb34f95f03fff27d739069b10f19ec2c060..635462d89a999eb020f7fbb3ea476dd5e7348606 100644 (file)
@@ -270,7 +270,7 @@ void XGUI_PreferencesDlg::modified(XGUI_Prefs& theModified) const
 void XGUI_PreferencesDlg::onDefault()
 {
   // reset main resources
-#ifdef WIN32
+#ifdef SALOME_750 // until SALOME 7.5.0 is released
   QtxResourceMgr::WorkingMode aPrev =
       myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
   myPreferences->retrieve();
index 1ed0d5f320cf419ca0258aecee3079c9096de4a8..390368256f94b36da8686400c094818381e47c3c 100644 (file)
@@ -137,7 +137,8 @@ void XGUI_AbstractRubberBand::updateMask()
   if (isClosed())\r
     r += createRegion(myPoints.last(), myPoints.first());\r
 \r
-  setMask(r);\r
+  if (!r.isEmpty())\r
+    setMask(r);\r
 }\r
 \r
 //**********************************************************\r
index b64386288fe908cad45948a44f5f7a6d6599e46e..b07d4676aa76480f9cc2b6e374390ad85db1d3d4 100644 (file)
@@ -22,6 +22,8 @@
 #include <TopoDS.hxx>
 #include <Visual3d_View.hxx>
 
+#include <math.h>
+
 #define BORDER_SIZE 2
 
 const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
index 22358aab96a01a69400684a6fc335bd2a2d5d9ed..1d72cff78d8cb26ae25ff9cebddb7fbbb925eb40 100644 (file)
@@ -1306,3 +1306,15 @@ void XGUI_Workshop::setDisplayMode(const QList<ObjectPtr>& theList, int theMode)
   if (theList.size() > 0)
     myDisplayer->updateViewer();
 }
+
+//**************************************************************
+void XGUI_Workshop::closeDocument()
+{
+  myDisplayer->closeLocalContexts();
+  myDisplayer->eraseAll();
+  objectBrowser()->clearContent();
+
+  SessionPtr aMgr = ModelAPI_Session::get();
+  aMgr->moduleDocument()->close();
+  objectBrowser()->clearContent();
+}
index d5159189aec9465cd207beae2dd10569b5746560..764e19f2d626079bbe01ce7dffca429f9ddd32ba 100644 (file)
@@ -214,6 +214,8 @@ signals:
 
   void activateLastPart();
 
+  void closeDocument();
+
  protected:
   bool event(QEvent * theEvent);
   //Event-loop processing methods: