]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authornds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 14:08:33 +0000 (18:08 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 14:08:33 +0000 (18:08 +0400)
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Circ.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Circ.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Circ2d.h
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetEditor.h
src/PartSet/PartSet_ConstraintRadiusPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp

index b268a83b652ec1083ad1d095d0f4beba812851ed..28187984c9d8037f1535e21b1b173a1682d65098 100644 (file)
@@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 
 SET(PROJECT_HEADERS
     GeomAPI.h
+    GeomAPI_Circ.h
     GeomAPI_Circ2d.h
     GeomAPI_Interface.h
     GeomAPI_XY.h
@@ -20,6 +21,7 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+    GeomAPI_Circ.cpp
     GeomAPI_Circ2d.cpp
     GeomAPI_Interface.cpp
     GeomAPI_XY.cpp
diff --git a/src/GeomAPI/GeomAPI_Circ.cpp b/src/GeomAPI/GeomAPI_Circ.cpp
new file mode 100644 (file)
index 0000000..811ef69
--- /dev/null
@@ -0,0 +1,63 @@
+// File:        GeomAPI_Circ2cpp
+// Created:     24 Jun 2014
+// Author:      Artem ZHIDKOV
+
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
+
+#include <gp_Dir.hxx>
+#include <gp_Circ.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Ax2.hxx>
+
+#include <Geom_Circle.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+
+#define MY_CIRC static_cast<gp_Circ*>(myImpl)
+
+static gp_Circ* newCirc(const gp_Pnt& theCenter,
+                        const gp_Dir& theDir,
+                        const double  theRadius)
+{
+  return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
+}
+
+GeomAPI_Circ::GeomAPI_Circ(const boost::shared_ptr<GeomAPI_Pnt>& theCenter,
+                           const boost::shared_ptr<GeomAPI_Dir>& theDir,
+                           double                                theRadius)
+  : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(),
+                              theDir->impl<gp_Dir>(), theRadius))
+{
+}
+
+const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  boost::shared_ptr<GeomAPI_Pnt> aResult;
+  if (!MY_CIRC)
+    return aResult;
+
+  Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
+
+  const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
+
+  GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
+  Standard_Integer aNbPoint = aProj.NbPoints();
+  if (aNbPoint > 0)
+  {
+    double aMinDistance = 0, aDistance;
+    for (Standard_Integer j = 1; j <= aNbPoint; j++)
+    {
+      gp_Pnt aNewPoint = aProj.Point(j);
+      aDistance = aNewPoint.Distance(aPoint);
+      if (!aMinDistance || aDistance < aMinDistance)
+      {
+        aMinDistance = aDistance;
+        aResult = boost::shared_ptr<GeomAPI_Pnt>(
+          new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
+      }
+    }
+  }
+  return aResult;
+}
+
diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h
new file mode 100644 (file)
index 0000000..c1a23bb
--- /dev/null
@@ -0,0 +1,32 @@
+// File:        GeomAPI_Circ.h
+// Created:     24 Jun 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GeomAPI_Circ_HeaderFile
+#define GeomAPI_Circ_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Pnt;
+class GeomAPI_Dir;
+
+/**\class GeomAPI_Circ
+ * \ingroup DataModel
+ * \brief Circle in 3D
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Circ: public GeomAPI_Interface
+{
+public:
+  /// Creation of circle defined by center point, direction and circle radius
+  GeomAPI_Circ(const boost::shared_ptr<GeomAPI_Pnt>& theCenter,
+               const boost::shared_ptr<GeomAPI_Dir>& theDir,
+               double theRadius);
+
+  /// Project point on circle
+  const boost::shared_ptr<GeomAPI_Pnt> project(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+};
+
+#endif
+
index 1870cbba80e160350ed0e6b7e1beae04af5b52b6..11d18f6b665abdb313630e0fbc30e19a23bb0691 100644 (file)
@@ -13,7 +13,7 @@ class GeomAPI_Dir2d;
 
 /**\class GeomAPI_Circ2d
  * \ingroup DataModel
- * \brief Line in 2D
+ * \brief Circle in 2D
  */
 
 class GEOMAPI_EXPORT GeomAPI_Circ2d: public GeomAPI_Interface
index 84b63cf2835e12c3ccd399b6cd76a872a158983c..f62eae3d3fbe4085328d8c643146d0e566c83850 100644 (file)
 
 #include <QWidget>
 #include <QLineEdit>
+#include <QTimer>
+#include <QDialog>
+#include <QLayout>
 
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)
+: ModuleBase_ModelWidget(theParent, theData), myValue(0)
 {
-  myEditor = new QLineEdit(0);
-  myEditor->setWindowFlags(Qt::ToolTip);
-  myEditor->setFocusPolicy(Qt::StrongFocus);
-
-  connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
-  connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged()));
 }
 
 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
-  delete myEditor;
+  //delete myEditor;
 }
 
 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
@@ -42,13 +39,9 @@ bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
   DataPtr aData = theFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
   bool isOk;
-  double aValue = myEditor->text().toDouble(&isOk);
-  if (isOk && aReal->value() != aValue) {
-    //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
-    //bool isBlocked = that->blockSignals(true);
-    aReal->setValue(aValue);
+  if (isOk && aReal->value() != myValue) {
+    aReal->setValue(myValue);
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-    //that->blockSignals(isBlocked);
   }
   return true;
 }
@@ -58,9 +51,7 @@ bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
 
-  //bool isBlocked = this->blockSignals(true);
-  myEditor->setText(QString::number(aRef->value()));
-  //this->blockSignals(isBlocked);
+  myValue = aRef->value();
   return true;
 }
 
@@ -68,11 +59,22 @@ void ModuleBase_WidgetEditor::focusTo()
 {
   QPoint aPoint = QCursor::pos();
 
-  myEditor->move(aPoint);
-  myEditor->show();
+  QDialog aDlg;
+  aDlg.setWindowFlags(Qt::FramelessWindowHint);
+  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+  aLay->setContentsMargins(0,0,0,0);
+
+  QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg);
+  connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
+  aLay->addWidget(aEditor);
+
+  aDlg.move(aPoint);
+  int aRes = aDlg.exec();
+
+  if (aRes == QDialog::Accepted)
+    myValue = aEditor->text().toDouble();
 
-  myEditor->selectAll();
-  myEditor->setFocus();
+  emit focusOutWidget(this);
 }
 
 QWidget* ModuleBase_WidgetEditor::getControl() const
@@ -86,8 +88,3 @@ QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
   return aControls;
 }
 
-void ModuleBase_WidgetEditor::onStopEditing()
-{
-  myEditor->hide();
-  emit focusOutWidget(this);
-}
index e2f67a0cbbf2ecd2576976f6046d2b0dbf0a76d4..ec670f402cb9deb3e50bb7ad51b29b024f4db1fc 100644 (file)
@@ -48,14 +48,10 @@ public:
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
-protected slots:
-  /// Slot to check the editing stop
-  void onStopEditing();
-
 private:
-  QLineEdit* myEditor;
   FeaturePtr myFeature; ///< the current widget feature
   QStringList myFeatureKinds; ///< the kinds of possible features
+  double myValue;
 };
 
 #endif
index b8f2a80103754912500c59d95995b07a97bb5e5c..659eff3f8170c2e0b7c27f699d4c82de2b50a73c 100644 (file)
@@ -106,101 +106,6 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double
   return aMode;
 }
 
-Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(FeaturePtr theFeature,
-                                                       FeaturePtr theSketch,
-                                                       Handle(AIS_InteractiveObject) thePreviuos)
-{
-  Handle(AIS_InteractiveObject) anAIS = thePreviuos;
-  if (!theFeature || !theSketch)
-    return anAIS;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-  if (!anAttr)
-    return anAIS;
-  FeaturePtr aFeature = anAttr->feature();
-  std::string aKind = aFeature ? aFeature->getKind() : "";
-  if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND)
-    return anAIS;
-
-  //boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-  //        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  //double aFlyout = aFlyoutAttr->value();
-  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  double aValue = aValueAttr->value();
-
-  // an anchor point
-  boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute
-                                                        (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
-  boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
-  boost::shared_ptr<GeomAPI_Pnt> anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch);
-  gp_Pnt anAnchorPoint = anAnchor->impl<gp_Pnt>();
-
-  std::string aCenterArgument;
-  double aRadius;
-  if (aKind == SKETCH_CIRCLE_KIND) {
-    aCenterArgument = CIRCLE_ATTR_CENTER;
-    bool isValid;
-    aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid);
-  }
-  else if (aKind == SKETCH_ARC_KIND) {
-    aCenterArgument = ARC_ATTR_CENTER;
-    aRadius = PartSet_FeatureArcPrs::radius(aFeature);
-  }
-
-  // a circle
-  boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterArgument));
-  boost::shared_ptr<GeomAPI_Pnt2d> aCenter2D = aCenterAttr->pnt();
-  boost::shared_ptr<GeomAPI_Pnt> aCenter = PartSet_Tools::point3D(aCenter2D, theSketch);
-
-  boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_NORM));
-  boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
-  const gp_Dir& aDir = aNormal->impl<gp_Dir>();
-
-  gp_Circ aCircle = gp_Circ(gp_Ax2(aCenter->impl<gp_Pnt>(), aDir), aRadius);
-  //boost::shared_ptr<GeomAPI_Shape> aShape;
-  //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor);
-    //boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
-
-  if (anAIS.IsNull())
-  {
-    Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aCircle, anAnchorPoint);
-    aDimAIS->SetCustomValue(aValue);
-    //Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aShape->impl<TopoDS_Shape>());
-
-    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
-    anAspect->MakeArrows3d (Standard_False);
-    anAspect->MakeText3d(false);
-    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
-    anAspect->MakeTextShaded(false);
-    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
-    aDimAIS->SetDimensionAspect (anAspect);
-    //aDimAIS->SetFlyout(aFlyout);
-    aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
-
-    anAIS = aDimAIS;
-  }
-  else {
-    // update presentation
-    Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
-    if (!aDimAIS.IsNull()) {
-      gp_Pnt anAPoint(anAnchorPoint.X(),anAnchorPoint.Y(),anAnchorPoint.Z());
-
-      aDimAIS->SetMeasuredGeometry(aCircle, anAnchorPoint);
-      aDimAIS->SetCustomValue(aValue);
-      //aDimAIS->SetMeasuredGeometry(aShape->impl<TopoDS_Shape>());
-      //aDimAIS->SetFlyout(aFlyout);
-      aDimAIS->Redisplay(Standard_True);
-    }
-  }
-  return anAIS;
-}
-
 void PartSet_ConstraintRadiusPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
                                                         gp_Pnt& thePoint, Handle(V3d_View) theView,
                                                         double& theX, double& theY)
index e316ab1f0b2452dfb5ead5b783b54e72f9ba6ad6..48585dcb633346e8b4e63e96789b315eff11ca10 100644 (file)
@@ -49,15 +49,6 @@ public:
   virtual PartSet_SelectionMode setPoint(double theX, double theY,
                                          const PartSet_SelectionMode& theMode);
 
-  /// Creates an AIS presentation if the previous is null or update the given one
-  /// \param theFeature a feature
-  /// \param theSketch a feature sketch
-  /// \param thePrevious a previuos AIS presentation
-  /// \return a created/changed AIS object with the feature parameters
-  static Handle_AIS_InteractiveObject createPresentation(FeaturePtr theFeature,
-                                                         FeaturePtr theSketch,
-                                                         Handle_AIS_InteractiveObject thePreviuos);
-
   /// Returns the feature attribute name for the selection mode
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
index f467923854add12550a488f6278afeb97e3e7a25..a57df918bd87de76a418d15b5c78b1b9613cfca2 100644 (file)
@@ -4,12 +4,20 @@
 
 #include "SketchPlugin_ConstraintRadius.h"
 
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
+
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ.h>
 #include <GeomDataAPI_Point2D.h>
-#include <SketchPlugin_Point.h>
+#include <GeomDataAPI_Dir.h>
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_RadiusDimension.hxx>
 
 SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
 {
@@ -31,7 +39,83 @@ void SketchPlugin_ConstraintRadius::execute()
 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
   Handle_AIS_InteractiveObject thePrevious)
 {
-  /// \todo Preview for diameter constraint
-  return thePrevious;
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  if (!sketch())
+    return anAIS;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  if (!anAttr)
+    return anAIS;
+  FeaturePtr aFeature = anAttr->feature();
+  std::string aKind = aFeature ? aFeature->getKind() : "";
+  if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND)
+    return anAIS;
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+
+  // an anchor point
+  boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
+  boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
+  boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
+
+  aData = aFeature->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
+  double aRadius;
+  if (aKind == SKETCH_CIRCLE_KIND) {
+    aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+    AttributeDoublePtr aCircRadius = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CIRCLE_ATTR_RADIUS));
+    aRadius = aCircRadius->value();
+  }
+  else if (aKind == SKETCH_ARC_KIND) {
+    aCenterAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+    boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+    aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+  }
+
+  // a circle
+  boost::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
+
+  boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(sketch()->data()->attribute(SKETCH_ATTR_NORM));
+  boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+
+  boost::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
+
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_RadiusDimension) aDimAIS = 
+      new AIS_RadiusDimension(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
+    aDimAIS->SetCustomValue(aValue);
+
+    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+    anAspect->MakeArrows3d (Standard_False);
+    anAspect->MakeText3d(false);
+    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
+    anAspect->MakeTextShaded(false);
+    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
+    aDimAIS->SetDimensionAspect (anAspect);
+    aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
+
+    anAIS = aDimAIS;
+  }
+  else
+  {
+    // update presentation
+    Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
+    if (!aDimAIS.IsNull())
+    {
+      aDimAIS->SetMeasuredGeometry(aCircle->impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
+      aDimAIS->SetCustomValue(aValue);
+      aDimAIS->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
 }