const static char* WDG_EXPR_EDITOR = "expr_editor";
const static char* WDG_PLACE_HOLDER = "placeholder";
const static char* WDG_ACTION = "action";
+const static char* WDG_POINT_INPUT = "point_input";
// Containers
const static char* WDG_GROUP = "groupbox";
const ModelHighAPI_Double& theZ)
{
//fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
- fillAttribute(theX, myx);
- fillAttribute(theY, myy);
- fillAttribute(theZ, myz);
+
+ // TODO: Fill point attribute
+ //fillAttribute(theX, myx);
+ //fillAttribute(theY, myy);
+ //fillAttribute(theZ, myz);
+
fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
execute(false);
if (aMeth == "" || // default is XYZ
aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
- theDumper << x() << ", " << y() << ", " << z();
+ theDumper << point() << ")" << std::endl;
} else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
const std::string anIntersectionType = intersectionType()->value();
if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
CONSTRUCTIONAPI_EXPORT
virtual ~ConstructionAPI_Point();
- INTERFACE_27(ConstructionPlugin_Point::ID(),
- x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
- y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
- z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
+ INTERFACE_25(ConstructionPlugin_Point::ID(),
+ point, ConstructionPlugin_Point::point3d(), GeomDataAPI_Point, /** Point attribute */,
creationMethod, ConstructionPlugin_Point::CREATION_METHOD(),
ModelAPI_AttributeString, /** Creation method */,
intersectionType, ConstructionPlugin_Point::INTERSECTION_TYPE(),
ModelAPI
GeomAPI
GeomAlgoAPI
+ GeomDataAPI
)
SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
../GeomAPI
../GeomAlgoAPI
../Events
+ ../GeomDataAPI
)
#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_Circ.h>
+#include <GeomDataAPI_Point.h>
+
#include <GeomAPI_Edge.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Vertex.h>
//==================================================================================================
void ConstructionPlugin_Point::initAttributes()
{
- data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(point3d(), GeomDataAPI_Point::typeId());
data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
//==================================================================================================
std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
{
- return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
- real(Y())->value(),
- real(Z())->value());
+ AttributePointPtr aPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(point3d()));
+ return GeomAlgoAPI_PointBuilder::vertex(aPoint->x(), aPoint->y(), aPoint->z());
}
//==================================================================================================
return MY_CREATION_METHOD_ID;
}
- /// Attribute name for X coordinate.
- inline static const std::string& X()
+ inline static const std::string& point3d()
{
- static const std::string POINT_ATTR_X("x");
- return POINT_ATTR_X;
- }
-
- /// Attribute name for Y coordinate.
- inline static const std::string& Y()
- {
- static const std::string POINT_ATTR_Y("y");
- return POINT_ATTR_Y;
- }
-
- /// Attribute name for Z coordinate.
- inline static const std::string& Z()
- {
- static const std::string POINT_ATTR_Z("z");
- return POINT_ATTR_Z;
+ static const std::string POINT_ATTR("point3d");
+ return POINT_ATTR;
}
/// Attribute name for selected edge.
title="By X, Y, Z"
tooltip="Point at a given distance from the origin."
icon="icons/Construction/point_by_xyz_32x32.png">
- <doublevalue id="x"
- label="X "
- tooltip="X coordinate."
- icon="icons/Construction/x_size.png"
- default="0"/>
- <doublevalue id="y"
- label="Y "
- tooltip="Y coordinate."
- icon="icons/Construction/y_size.png"
- default="0"/>
- <doublevalue id="z"
- label="Z "
- tooltip="Z coordinate."
- icon="icons/Construction/z_size.png"
- default="0"/>
+ <point_input id="point3d"/>
</box>
<box id="by_distance_on_edge"
title="By distance on edge"
#include <ModelAPI_Events.h>
#include <ModelAPI_Result.h>
+#include <GeomDataAPI_Point.h>
+
#include <Events_Message.h>
#include <Events_InfoMessage.h>
double theX, double theY, double theZ)
{
std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
- //aPoint->string("creation_method")->setValue("by_xyz");
- aPoint->real("x")->setValue(theX);
- aPoint->real("y")->setValue(theY);
- aPoint->real("z")->setValue(theZ);
+ AttributePointPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>
+ (aPoint->data()->attribute("point3d"));
+ aPointAttr->setValue(theX, theY, theZ);
aPoint->string("creation_method")->setValue("by_xyz");
aPoint->data()->setName(theName);
// don't show automatically created feature in the features history
ModuleBase_ChoiceCtrl.h
ModuleBase_WidgetNameEdit.h
ModuleBase_WidgetRadiobox.h
+ ModuleBase_WidgetPointInput.h
)
SET(PROJECT_MOC_HEADERS
ModuleBase_ChoiceCtrl.h
ModuleBase_WidgetNameEdit.h
ModuleBase_WidgetRadiobox.h
+ ModuleBase_WidgetPointInput.h
)
SET(PROJECT_SOURCES
ModuleBase_ChoiceCtrl.cpp
ModuleBase_WidgetNameEdit.cpp
ModuleBase_WidgetRadiobox.cpp
+ ModuleBase_WidgetPointInput.cpp
)
SET(PROJECT_LIBRARIES
double ModuleBase_ParamSpinBox::value() const
{
+ std::string aa = lineEdit()->text().toStdString();
return lineEdit()->text().toDouble();
}
#include <ModuleBase_WidgetExprEditor.h>
#include <ModuleBase_WidgetCreatorFactory.h>
#include <ModuleBase_WidgetAction.h>
+#include <ModuleBase_WidgetPointInput.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
result = NULL;
} else if (theType == WDG_ACTION) {
result = new ModuleBase_WidgetAction(theParent, myWidgetApi);
+ } else if (theType == WDG_POINT_INPUT) {
+ result = new ModuleBase_WidgetPointInput(theParent, myWorkshop, myWidgetApi);
} else {
result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi);
if (!result)
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "ModuleBase_WidgetPointInput.h"
+#include "ModuleBase_Tools.h"
+#include "ModuleBase_ParamSpinBox.h"
+#include "ModuleBase_ViewerPrs.h"
+
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Pnt.h>
+
+#include <GeomDataAPI_Point.h>
+
+#include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
+
+#include <QFormLayout>
+#include <QLabel>
+
+ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData)
+ : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
+{
+ bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
+
+ QFormLayout* aMainlayout = new QFormLayout(this);
+ ModuleBase_Tools::adjustMargins(aMainlayout);
+
+ myXSpin = new ModuleBase_ParamSpinBox(this);
+ myXSpin->setAcceptVariables(aAcceptVariables);
+ myXSpin->setToolTip("X coordinate");
+ myXSpin->setValue(0);
+ QLabel* aXLbl = new QLabel(this);
+ aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
+ aMainlayout->addRow(aXLbl, myXSpin);
+
+ myYSpin = new ModuleBase_ParamSpinBox(this);
+ myYSpin->setAcceptVariables(aAcceptVariables);
+ myYSpin->setToolTip("Y coordinate");
+ myYSpin->setValue(0);
+ QLabel* aYLbl = new QLabel(this);
+ aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
+ aMainlayout->addRow(aYLbl, myYSpin);
+
+ myZSpin = new ModuleBase_ParamSpinBox(this);
+ myZSpin->setAcceptVariables(aAcceptVariables);
+ myZSpin->setToolTip("Z coordinate");
+ myZSpin->setValue(0);
+ QLabel* aZLbl = new QLabel(this);
+ aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
+ aMainlayout->addRow(aZLbl, myZSpin);
+}
+
+ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
+{
+
+}
+
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
+{
+ QList<QWidget*> aList;
+ aList.append(myXSpin);
+ aList.append(myYSpin);
+ aList.append(myZSpin);
+ return aList;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetPointInput::storeValueCustom()
+{
+ AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
+ if (aAttr.get()) {
+ if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
+ aAttr->setText(myXSpin->text().toStdString(),
+ myYSpin->text().toStdString(), myZSpin->text().toStdString());
+ } else {
+ aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
+ }
+ return true;
+ }
+ return false;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetPointInput::restoreValueCustom()
+{
+ AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
+ if (aAttr.get()) {
+ std::string aXText = aAttr->textX();
+ if (aXText.empty()) {
+ myXSpin->setValue(aAttr->x());
+ } else {
+ myXSpin->setText(aXText.c_str());
+ }
+ std::string aYText = aAttr->textY();
+ if (aYText.empty()) {
+ myYSpin->setValue(aAttr->y());
+ } else {
+ myYSpin->setText(aYText.c_str());
+ }
+ std::string aZText = aAttr->textZ();
+ if (aZText.empty()) {
+ myZSpin->setValue(aAttr->z());
+ } else {
+ myZSpin->setText(aZText.c_str());
+ }
+ return true;
+ }
+ return false;
+}
+
+//********************************************************************
+void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
+{
+ theModuleSelectionModes = -1;
+ theModes << TopAbs_VERTEX;
+}
+
+//********************************************************************
+QIntList ModuleBase_WidgetPointInput::shapeTypes() const
+{
+ QIntList aList;
+ aList << TopAbs_VERTEX;
+ return aList;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetPointInput
+::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
+{
+ GeomShapePtr aShape = thePrs->shape();
+ if (aShape->isVertex()) {
+ GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
+ GeomPointPtr aPnt = aVertex->point();
+ myXSpin->setValue(aPnt->x());
+ myYSpin->setValue(aPnt->y());
+ myZSpin->setValue(aPnt->z());
+ return true;
+ }
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef ModuleBase_WidgetPointInput_H
+#define ModuleBase_WidgetPointInput_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_WidgetSelector.h"
+
+class ModuleBase_ParamSpinBox;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetPointInput : public ModuleBase_WidgetSelector
+{
+ Q_OBJECT
+public:
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theWorkshop a current workshop
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData);
+
+ /// Destructor
+ virtual ~ModuleBase_WidgetPointInput();
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ /// Saves the internal parameters to the given feature
+ /// \return True in success
+ virtual bool storeValueCustom();
+
+ /// Restore value from attribute data to the widget's control
+ virtual bool restoreValueCustom();
+
+ /// Defines if it is supposed that the widget should interact with the viewer.
+ virtual bool isViewerSelector() { return true; }
+
+ /// Fills given container with selection modes if the widget has it
+ /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
+ /// \param [out] theModes a container of modes
+ virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param thePrs a selected owner
+ virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
+protected:
+ /// Retunrs a list of possible shape types
+ /// \return a list of shapes
+ virtual QIntList shapeTypes() const;
+
+protected:
+ ModuleBase_ParamSpinBox* myXSpin;
+ ModuleBase_ParamSpinBox* myYSpin;
+ ModuleBase_ParamSpinBox* myZSpin;
+};
+
+
+#endif
\ No newline at end of file