]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authorszy <szy@opencascade.com>
Tue, 30 Dec 2014 09:52:39 +0000 (12:52 +0300)
committerszy <szy@opencascade.com>
Tue, 30 Dec 2014 09:52:39 +0000 (12:52 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/Model/Model_AttributeSelection.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/SketchPlugin/SketchPlugin_Plugin.cpp

index 2dc527d9d5462e97016396853b31144b6e9f754a..6f262f536531617248435a95f8b60710a3072650 100644 (file)
@@ -69,4 +69,4 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::
   std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
   aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
   return aRes;
-}
\ No newline at end of file
+}
index ff46a56abbd467cdec624fc337f84c394519ef9f..8f60cf0593ef611d9b4fcbcebd03a58bb553cd83 100644 (file)
@@ -81,16 +81,19 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
 
   // do noth use naming if selected shape is result shape itself, but not sub-shape
   TDF_Label aSelLab = selectionLabel();
-  if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
-    aSelLab.ForgetAllAttributes(true);
-    TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
-  } else {
-    aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
-    if (theContext->groupName() == ModelAPI_ResultBody::group())
+  aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
+  if (theContext->groupName() == ModelAPI_ResultBody::group()) {
+    // do not select the whole shape for body:it is already must be in the data framework
+    if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
+      aSelLab.ForgetAllAttributes(true);
+      TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
+    } else {
       selectBody(theContext, theSubShape);
-    else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
-      selectConstruction(theContext, theSubShape);
+    }
+  } else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) {
+    selectConstruction(theContext, theSubShape);
   }
+  myIsInitialized = true;
 
   std::string aSelName = namingName();
   if(!aSelName.empty())
@@ -102,7 +105,6 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   //selectSubShape("EDGE", "Extrusion_1/TopFace|Extrusion_1/LateralFace_1");
   //selectSubShape("EDGE", "Sketch_1/Edge_6");
 #endif
-  myIsInitialized = true;
   owner()->data()->sendAttributeUpdated(this);
 }
 
@@ -349,6 +351,7 @@ bool Model_AttributeSelection::update()
         }
       }
     } else { // simple construction element: the selected is that needed
+      selectConstruction(aContext, aContext->shape());
       owner()->data()->sendAttributeUpdated(this);
       return true;
     }
@@ -399,11 +402,11 @@ static void registerSubShape(TDF_Label& theMainLabel, TopoDS_Shape theShape,
   else if (theShape.ShapeType() == TopAbs_VERTEX) aName<<"Vertex";
 
   if (theRefs.IsNull()) {
-    aName<<"_"<<theID;
+    aName<<theID;
   } else { // make a compisite name from all sub-elements indexes: "1_2_3_4"
     TColStd_MapIteratorOfPackedMapOfInteger aRef(theRefs->GetMap());
     for(; aRef.More(); aRef.Next()) {
-      aName<<"_"<<aRef.Key();
+      aName<<"-"<<aRef.Key();
     }
   }
 
@@ -419,13 +422,18 @@ void Model_AttributeSelection::selectConstruction(
   FeaturePtr aContextFeature = theContext->document()->feature(theContext);
   CompositeFeaturePtr aComposite = 
     std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+  const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
   if (!aComposite || aComposite->numberOfSubs() == 0) {
-    return; // saving of context is enough: result construction contains exactly the needed shape
+    // saving of context is enough: result construction contains exactly the needed shape
+    TNaming_Builder aBuilder(selectionLabel());
+    aBuilder.Generated(aSubShape);
+    aMyDoc->addNamingName(selectionLabel(), theContext->data()->name());
+    TDataStd_Name::Set(selectionLabel(), theContext->data()->name().c_str());
+    return;
   }
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(owner()->data());
   TDF_Label aLab = myRef.myRef->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);
index c1348168e8dd5be66e7c0312af78dbb61aa8bc44..e3807bd7ec4cae95a3c9c0836339f2ff58b76d71 100644 (file)
@@ -303,7 +303,7 @@ void PartSet_Module::onNoMoreWidgets()
   }
 }
 
-void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
+void PartSet_Module::onVertexSelected()
 {
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
@@ -335,8 +335,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aWgt->setWorkshop(aWorkshop);
     aWgt->setSketch(mySketchMgr->activeSketch());
 
-    connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), 
-      this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
+    connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
index 8fa932b39f21b9d24a6fd77d9e6d04a65b448ae0..9723d53e3684b01f6fb42840e34ff0bdcd32c86d 100644 (file)
@@ -122,7 +122,7 @@ protected slots:
   virtual void registerFilters();
 
  private slots:
-   void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+   void onVertexSelected();
 
 
  private:
index 78df67edb61f3a0f9a98e7400a2e967329eb67e8..0b07da7e75db47c670207a7138059a3b9048c0fe 100644 (file)
@@ -308,6 +308,35 @@ void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
     aFeature->execute();
 }
 
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+  findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
+  double theTolerance, const QList<FeaturePtr>& theIgnore)
+{
+  std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+      new GeomAPI_Pnt2d(theX, theY));
+
+  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+  for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+    FeaturePtr aFeature = theSketch->subFeature(i);
+    if (!theIgnore.contains(aFeature)) {
+      anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+
+      std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
+      for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
+        std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+        double x = aCurPoint->x();
+        double y = aCurPoint->y();
+        if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
+          return aCurPoint;
+        }
+      }
+    }
+  }
+  return std::shared_ptr<GeomDataAPI_Point2D>();
+}
+
+
 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
                                    const std::string& theAttribute, double theClickedX,
                                    double theClickedY)
@@ -338,10 +367,12 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
         aLast = anAttiributes.end();
     std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
     for (; anIt != aLast && !aFPoint; anIt++) {
-      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
-          GeomDataAPI_Point2D>(*anIt);
-      if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
+      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+      if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
         aFPoint = aCurPoint;
+        break;
+      }
     }
     if (aFPoint)
       PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
@@ -353,23 +384,25 @@ std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theS
   std::shared_ptr<GeomAPI_Pln> aPlane;
 
   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-  if (aNormal && anOrigin) {
-    double adX = aNormal->x();
-    double adY = aNormal->y();
-    double adZ = aNormal->z();
-
-    if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
-      double aX = anOrigin->x();
-      double aY = anOrigin->y();
-      double aZ = anOrigin->z();
-      gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
-      double aA, aB, aC, aD;
-      aPln.Coefficients(aA, aB, aC, aD);
-      aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+  if (aData) {
+    std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+        aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+    if (aNormal && anOrigin) {
+      double adX = aNormal->x();
+      double adY = aNormal->y();
+      double adZ = aNormal->z();
+
+      if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
+        double aX = anOrigin->x();
+        double aY = anOrigin->y();
+        double aZ = anOrigin->z();
+        gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
+        double aA, aB, aC, aD;
+        aPln.Coefficients(aA, aB, aC, aD);
+        aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+      }
     }
   }
   return aPlane;
index e3579c9f56b5958559ce8d88e132381a1d696284..05104bb016714dc2e42ab9d47173c04d054c753a 100644 (file)
@@ -78,6 +78,9 @@ class PARTSET_EXPORT PartSet_Tools
   static std::shared_ptr<ModelAPI_Document> document();
 
 
+  static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
+    double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+
   /// Returns a point attribute of the feature by the coordinates if it is
   /// \param theFeature the feature
   /// \param theX the horizontal coordinate
index 26f8f65374be43e28cf5a2853e35c86f50a1da93..5baa133e7e279303c0581dfd5c2d065cc1edcc8c 100644 (file)
@@ -229,27 +229,44 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-  NCollection_List<TopoDS_Shape> aShapes;
-  std::list<ObjectPtr> aObjects;
-  aSelection->selectedShapes(aShapes, aObjects);
-  if (aShapes.Extent() > 0) {
-    TopoDS_Shape aShape = aShapes.First();
-    double aX, aY;
-    if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
-      setPoint(aX, aY);
-
-      PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
-      emit vertexSelected(aObjects.front(), aShape);
-      emit focusOutWidget(this);
-      return;
-    }
-  }
+  // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
+  //NCollection_List<TopoDS_Shape> aShapes;
+  //std::list<ObjectPtr> aObjects;
+  //aSelection->selectedShapes(aShapes, aObjects);
+  //if (aShapes.Extent() > 0) {
+  //  TopoDS_Shape aShape = aShapes.First();
+  //  double aX, aY;
+  //  if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
+  //    setPoint(aX, aY);
+
+  //    PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+  //    emit vertexSelected(aObjects.front(), aShape);
+  //    emit focusOutWidget(this);
+  //    return;
+  //  }
+  //}
+  // End of Bug dependent fragment
+
   // A case when point is taken from mouse event
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
   double aX, anY;
-  PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+  Handle(V3d_View) aView = theWnd->v3dView();
+  PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
   setPoint(aX, anY);
 
+  std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+  QList<FeaturePtr> aIgnore;
+  aIgnore.append(feature());
+
+  double aTolerance = aView->Convert(4);
+  std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
+    PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+  if (aAttrPnt.get() != NULL) {
+
+    PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+    emit vertexSelected();
+  }
   emit focusOutWidget(this);
 }
 
index 69e6461ea75b3038667c4743ee9d75c0f2f00dd6..ad0395461f2375f1ac8a4b0c2ad3578f4b69c23a 100644 (file)
@@ -92,7 +92,7 @@ signals:
   /// Signal about selection of an existing vertex from an object
   /// \param theObject - the selected object
   /// \param theShape - the selected shape
-  void vertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+  void vertexSelected();
 
 protected slots:
   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
index 6680aef33008ad4a073d0ed3e3e6b7eebdc207f5..452e07401f313c26d1d867ccaf2f0182f2b86f06 100644 (file)
@@ -129,21 +129,23 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       std::dynamic_pointer_cast<SketchPlugin_Sketch>(theFeature);
   if (aSketchFeature.get()) {
     std::shared_ptr<ModelAPI_Data> aData = aSketchFeature->data();
-    std::shared_ptr<GeomDataAPI_Dir> aNormal =
-      std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-    aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-
-    aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
-    aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+    if (aData) {
+      std::shared_ptr<GeomDataAPI_Dir> aNormal =
+        std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+      aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+
+      aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+    }
   }
   return aMsg;
 }