]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Fri, 20 Jun 2014 11:53:50 +0000 (15:53 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 20 Jun 2014 11:53:50 +0000 (15:53 +0400)
1. Remove operation constraint class.
2. Edit constraint lenght. To debug

src/PartSet/CMakeLists.txt
src/PartSet/PartSet_FeatureLengthPrs.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationConstraint.cpp [deleted file]
src/PartSet/PartSet_OperationConstraint.h [deleted file]
src/PartSet/PartSet_OperationEditConstraint.cpp
src/PartSet/PartSet_OperationEditConstraint.h

index 254cd957226fca26d3fd5e979e5ee2f888e53672..800a4d5933de8009fd8603dacf60aa98cd642080 100644 (file)
@@ -14,7 +14,6 @@ SET(PROJECT_HEADERS
        PartSet_FeaturePointPrs.h
        PartSet_Listener.h
        PartSet_Module.h
-       PartSet_OperationConstraint.h
        PartSet_OperationCreateConstraint.h
        PartSet_OperationCreateFeature.h
        PartSet_OperationEditConstraint.h
@@ -36,7 +35,6 @@ SET(PROJECT_SOURCES
        PartSet_FeaturePointPrs.cpp
        PartSet_Listener.cpp
        PartSet_Module.cpp
-       PartSet_OperationConstraint.cpp
        PartSet_OperationCreateConstraint.cpp
        PartSet_OperationCreateFeature.cpp
        PartSet_OperationEditConstraint.cpp
index 36bc766ea57237d699add8c1605a6780030131fb..26b4bee77de44b5a306f0053ec1c5e394fd5dc54 100644 (file)
@@ -42,11 +42,6 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the
   PartSet_SelectionMode aMode = theMode;
   switch (theMode)
   {
-    case SM_FirstPoint: {
-      //PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
-      //aMode = SM_SecondPoint;
-    }
-    break;
     case SM_SecondPoint: {
       boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
       boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
@@ -85,56 +80,21 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the
 
 std::string PartSet_FeatureLengthPrs::getAttribute(const PartSet_SelectionMode& theMode) const
 {
-  std::string aAttribute;
-  switch (theMode)
-  {
-    case SM_FirstPoint:
-      //aAttribute = CIRCLE_ATTR_CENTER;
-    break;
-    case SM_SecondPoint:
-      //aAttribute = CIRCLE_ATTR_RADIUS;
-    break;
-    default:
-    break;
-  }
-  return aAttribute;
+  return "";
 }
 
 PartSet_SelectionMode PartSet_FeatureLengthPrs::getNextMode(const std::string& theAttribute) const
 {
-  PartSet_SelectionMode aMode = SM_SecondPoint;
-
-  /*if (theAttribute == CIRCLE_ATTR_CENTER)
-    aMode = SM_SecondPoint;
-  else if (theAttribute == CIRCLE_ATTR_RADIUS)
-    aMode = SM_DonePoint;*/
-  return aMode;
+  return SM_FirstPoint;
 }
 
 void PartSet_FeatureLengthPrs::move(double theDeltaX, double theDeltaY)
 {
-  /*boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-  if (!aData->isValid())
-    return;
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
-  aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);*/
 }
 
 double PartSet_FeatureLengthPrs::distanceToPoint(FeaturePtr theFeature,
                                                  double theX, double theY)
 {
-  /*double aDelta = 0;
-  if (!theFeature || theFeature->getKind() != getKind())
-    return aDelta;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
-
-  boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
-  return aPoint->pnt()->distance(aPoint2d);*/
   return 0;
 }
 
@@ -142,35 +102,12 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLengthPrs::findPoint(Featu
                                                                            double theX, double theY)
 {
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
-  /*if (!theFeature || theFeature->getKind() != getKind())
-    return aPoint2D;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
-  if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
-    aPoint2D = aPoint;
-*/
   return aPoint2D;
 }
 
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLengthPrs::featurePoint
                                                      (const PartSet_SelectionMode& theMode)
 {
-  /*std::string aPointArg;
-  switch (theMode)
-  {
-    case SM_FirstPoint:
-      aPointArg = CIRCLE_ATTR_CENTER;
-      break;
-    default:
-      break;
-  }
-  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                              (aData->attribute(aPointArg));
-  return aPoint;
-  */
   return boost::shared_ptr<GeomDataAPI_Point2D>();
 }
 
index ab0ad429bebdb06099a4f7f8da495de59f30e0cc..c1ca60f1407c7c2c7102189d9c9c92a7df46c91d 100644 (file)
@@ -3,7 +3,6 @@
 #include <PartSet_OperationCreateFeature.h>
 #include <PartSet_OperationEditFeature.h>
 #include <PartSet_OperationEditConstraint.h>
-#include <PartSet_OperationConstraint.h>
 #include <PartSet_OperationCreateConstraint.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
@@ -350,8 +349,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
       anOperation = new PartSet_OperationCreateConstraint(theCmdId.c_str(), this, aSketch);
     else if (theCmdId == PartSet_OperationEditConstraint::Type())
       anOperation = new PartSet_OperationEditConstraint(theCmdId.c_str(), this, aSketch);
-    else if (theCmdId == PartSet_OperationConstraint::Type())
-      anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch);
   }
 
   if (!anOperation) {
diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp
deleted file mode 100644 (file)
index 9b1d212..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-// File:        PartSet_OperationConstraint.h
-// Created:     20 Apr 2014
-// Author:      Natalia ERMOLAEVA
-
-#include <PartSet_OperationConstraint.h>
-
-#include <PartSet_Tools.h>
-#include <PartSet_OperationSketch.h>
-#include <SketchPlugin_ConstraintLength.h>
-
-#include <SketchPlugin_Feature.h>
-#include <SketchPlugin_Sketch.h>
-
-#include <GeomDataAPI_Point2D.h>
-
-#include <ModuleBase_OperationDescription.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_AttributeDouble.h>
-
-#include <SketchPlugin_Constraint.h>
-
-#include <Geom_Line.hxx>
-#include <gp_Lin.hxx>
-
-#include <XGUI_ViewerPrs.h>
-#include <XGUI_Constants.h>
-
-#include <SketchPlugin_Line.h>
-
-#include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-#include <QMouseEvent>
-
-using namespace std;
-
-PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId,
-                                                 QObject* theParent,
-                                              FeaturePtr theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
-{
-}
-
-PartSet_OperationConstraint::~PartSet_OperationConstraint()
-{
-}
-
-std::string PartSet_OperationConstraint::Type()
-{
-  return SKETCH_CONSTRAINT_LENGTH_KIND;
-}
-
-bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const
-{
-  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
-}
-
-void PartSet_OperationConstraint::init(FeaturePtr theFeature,
-                                       const std::list<XGUI_ViewerPrs>& /*theSelected*/,
-                                       const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
-  //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
-  //  return;
-  // use the last point of the previous feature as the first of the new one
-  //boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  //myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-}
-
-FeaturePtr PartSet_OperationConstraint::sketch() const
-{
-  return mySketch;
-}
-
-void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                const std::list<XGUI_ViewerPrs>& theSelected,
-                                                const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
-  if (theSelected.empty()) {
-  }
-  else {
-    XGUI_ViewerPrs aPrs = theSelected.front();
-    FeaturePtr aFeature = aPrs.feature();
-
-    setFeature(aFeature);
-    setValue(120);
-    flushUpdated();
-  }
-}
-
-void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
-{
-}
-
-void PartSet_OperationConstraint::startOperation()
-{
-  PartSet_OperationSketchBase::startOperation();
-  //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
-
-  emit multiSelectionEnabled(false);
-}
-
-void PartSet_OperationConstraint::abortOperation()
-{
-  emit featureConstructed(feature(), FM_Hide);
-  PartSet_OperationSketchBase::abortOperation();
-}
-
-void PartSet_OperationConstraint::stopOperation()
-{
-  PartSet_OperationSketchBase::stopOperation();
-  emit multiSelectionEnabled(true);
-}
-
-void PartSet_OperationConstraint::afterCommitOperation()
-{
-  PartSet_OperationSketchBase::afterCommitOperation();  
-  emit featureConstructed(feature(), FM_Deactivation);
-}
-
-FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage)
-{
-  FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
-  if (sketch()) {
-    boost::shared_ptr<SketchPlugin_Feature> aFeature = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
-
-    aFeature->addSub(aNewFeature);
-  }
-  /*if (myInitPoint) {
-    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
-    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
-
-    boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                (aData->attribute(LINE_ATTR_START));
-    PartSet_Tools::createConstraint(myInitPoint, aPoint);
-  }*/
-
-  emit featureConstructed(aNewFeature, FM_Activation);
-  if (theFlushMessage)
-    flushCreated();
-  return aNewFeature;
-}
-
-void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature)
-{
-  if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
-    return;
-
-  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-  anAttr->setFeature(theFeature);
-}
-
-void PartSet_OperationConstraint::setValue(const double theValue)
-{
-  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
-  AttributeDoublePtr anAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  anAttr->setValue(theValue);
-
-}
diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h
deleted file mode 100644 (file)
index 56ffe26..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-// File:        PartSet_OperationConstraint.h
-// Created:     20 Apr 2014
-// Author:      Natalia ERMOLAEVA
-
-#ifndef PartSet_OperationConstraint_H
-#define PartSet_OperationConstraint_H
-
-#include "PartSet.h"
-
-#include <PartSet_OperationSketchBase.h>
-
-#include <QObject>
-
-/*!
- \class PartSet_OperationConstraint
- * \brief The operation for the sketch constraint feature creation
-*/
-class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase
-{
-  Q_OBJECT
-
-public:
-  /// Returns the operation type key
-  static std::string Type();
-
-public:
-  /// Constructor
-  /// \param theId the feature identifier
-  /// \param theParent the operation parent
-  /// \param theFeature the parent feature
-  PartSet_OperationConstraint(const QString& theId, QObject* theParent,
-                              FeaturePtr theSketchFeature);
-  /// Destructor
-  virtual ~PartSet_OperationConstraint();
-
-  /// Returns that this operator can be started above already running one.
-   /// The runned operation should be the sketch feature modified operation
-  /// \param theOperation the previous running operation
-  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
-
-  /// Initializes some fields accorging to the feature
-  /// \param theSelected the list of selected presentations
-  /// \param theHighlighted the list of highlighted presentations
-  virtual void init(FeaturePtr theFeature,
-                    const std::list<XGUI_ViewerPrs>& theSelected,
-                    const std::list<XGUI_ViewerPrs>& theHighlighted);
-
-  /// Returns the operation sketch feature
-  /// \returns the sketch instance
-  virtual FeaturePtr sketch() const;
-
-  /// Gives the current selected objects to be processed by the operation
-  /// \param theEvent the mouse event
-  /// \param theView a viewer to have the viewer the eye position
-  /// \param theSelected the list of selected presentations
-  /// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<XGUI_ViewerPrs>& theSelected,
-                            const std::list<XGUI_ViewerPrs>& theHighlighted);
-  /// Gives the current mouse point in the viewer
-  /// \param thePoint a point clicked in the viewer
-  /// \param theEvent the mouse event
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
-
-protected:
-  /// \brief Virtual method called when operation is started
-  /// Virtual method called when operation started (see start() method for more description)
-  /// After the parent operation body perform, set sketch feature to the created line feature
-  virtual void startOperation();
-
-  /// Virtual method called when operation aborted (see abort() method for more description)
-  /// Before the feature is aborted, it should be hidden from the viewer
-  virtual void abortOperation();
-
-  /// Virtual method called when operation stopped - committed or aborted.
-  /// Restore the multi selection state
-  virtual void stopOperation();
-
-  /// Virtual method called after operation committed (see commit() method for more description)
-  virtual void afterCommitOperation();
-
-  /// Creates an operation new feature
-  /// In addition to the default realization it appends the created line feature to
-  /// the sketch feature
-  /// \param theFlushMessage the flag whether the create message should be flushed
-  /// \returns the created feature
-  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
-
-  /// Set the feature for the constraint
-  /// \param theFeature the line feature
-  void setFeature(FeaturePtr theFeature);
-
-  /// Set the value for the constraint
-  /// \param theValue the constraint value
-  void setValue(const double theValue);
-
-private:
-  FeaturePtr mySketch; ///< the sketch feature
-};
-
-#endif
index 53f7cc54911f9cd4e390a25b42ae3736426d32b0..18857be2595801dc7eb13cfff0a485c56fe3b490 100644 (file)
@@ -6,6 +6,7 @@
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketch.h>
 #include <PartSet_EditLine.h>
+#include <PartSet_FeaturePrs.h>
 #include <SketchPlugin_ConstraintLength.h>
 
 #include <ModuleBase_OperationDescription.h>
@@ -40,6 +41,9 @@ PartSet_OperationEditConstraint::PartSet_OperationEditConstraint(const QString&
                                               FeaturePtr theFeature)
 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
 {
+  std::string aKind = theId.toStdString();
+  myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature);
+
   // changed
   myEditor = new PartSet_EditLine(0);
   connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
@@ -90,7 +94,7 @@ FeaturePtr PartSet_OperationEditConstraint::sketch() const
 }
 
 void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                             const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                             const std::list<XGUI_ViewerPrs>& theSelected,
                                              const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
   //if (myFeatures.size() == 1)
@@ -98,6 +102,8 @@ void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle
     FeaturePtr aFeature;
     if (!theHighlighted.empty())
       aFeature = theHighlighted.front().feature();
+    if (!aFeature && !theSelected.empty()) // changed
+      aFeature = theSelected.front().feature();
 
     if (aFeature && aFeature == feature()) { // continue the feature edit
     }
@@ -135,10 +141,12 @@ void PartSet_OperationEditConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V
     double aX, anY;
     PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
 
-    double aDeltaX = aX - aCurX;
+    /*double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
 
-    PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);
+    PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);*/
+    myFeaturePrs->setPoint(aX, anY, SM_SecondPoint);
+
 
     /*std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
     for (; anIt != aLast; anIt++) {
index 41700b6e7283d251b8b7cfb36a42a6311f0958e8..8aaaa452f0ccf750a4dde65fcd6a5e3a494b6c35 100644 (file)
@@ -11,6 +11,7 @@
 #include <QObject>
 
 class PartSet_EditLine;
+class PartSet_FeaturePrs;
 class QMouseEvent;
 
 /*!
@@ -146,6 +147,7 @@ protected slots:
 
 private:
   PartSet_EditLine* myEditor; ///< the constraint value editor
+  boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
   FeaturePtr mySketch; ///< the sketch feature
   //std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
   Point myCurPoint; ///< the current 3D point clicked or moved