// Widgets
const static char* WDG_INFO = "label";
const static char* WDG_DOUBLEVALUE = "doublevalue";
+const static char* WDG_INTEGERVALUE = "integervalue";
const static char* WDG_BOOLVALUE = "boolvalue";
const static char* WDG_STRINGVALUE = "stringvalue";
const static char* WDG_MULTISELECTOR = "multi_selector";
#include "GeomValidators_Positive.h"
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
bool GeomValidators_Positive::isValid(
const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
{
- std::shared_ptr<ModelAPI_AttributeDouble> aDouble =
+ AttributeDoublePtr aDouble =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
- return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+ if (aDouble.get())
+ return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+ AttributeIntegerPtr aInteger =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
+ return aInteger->isInitialized() && aInteger->value() > 0;
}
ModuleBase_WidgetValidated.h
ModuleBase_WidgetExprEditor.h
ModuleBase_ParamSpinBox.h
+ ModuleBase_WidgetIntValue.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetExprEditor.cpp
ModuleBase_ParamSpinBox.cpp
ModuleBase_SelectionValidator.cpp
+ ModuleBase_WidgetIntValue.cpp
)
SET(PROJECT_LIBRARIES
#include <ModuleBase_WidgetSwitch.h>
#include <ModuleBase_WidgetShapeSelector.h>
#include <ModuleBase_WidgetDoubleValue.h>
+#include <ModuleBase_WidgetIntValue.h>
#include <ModuleBase_WidgetBoolValue.h>
#include <ModuleBase_WidgetFileSelector.h>
#include <ModuleBase_WidgetChoice.h>
result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_DOUBLEVALUE) {
result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
+ } else if (theType == WDG_INTEGERVALUE) {
+ result = new ModuleBase_WidgetIntValue(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_SHAPE_SELECTOR) {
result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
} else if (theType == WDG_BOOLVALUE) {
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_Widgets.h
+// Created: 04 June 2014
+// Author: Vitaly Smetannikov
+
+#include <ModuleBase_WidgetIntValue.h>
+#include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Data.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <ModelAPI_Events.h>
+
+#include <QWidget>
+#include <QFormLayout>
+#include <QLabel>
+#include <QEvent>
+#include <QTimer>
+#include <QSpinBox>
+
+#include <math.h>
+
+#ifndef INT_MAX
+#define INT_MAX 2147483647
+#endif
+
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
+ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+ QFormLayout* aControlLay = new QFormLayout(this);
+ ModuleBase_Tools::adjustMargins(aControlLay);
+
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, this);
+ if (!aLabelIcon.isEmpty())
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+
+ mySpinBox = new QSpinBox(this);
+ QString anObjName = QString::fromStdString(attributeID());
+ mySpinBox->setObjectName(anObjName);
+
+ bool isOk = false;
+ std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
+ int aMinVal = QString::fromStdString(aProp).toInt(&isOk);
+ if (isOk) {
+ mySpinBox->setMinimum(aMinVal);
+ } else {
+ mySpinBox->setMinimum(-INT_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_MAX);
+ int aMaxVal = QString::fromStdString(aProp).toInt(&isOk);
+ if (isOk) {
+ mySpinBox->setMaximum(aMaxVal);
+ } else {
+ mySpinBox->setMaximum(INT_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_STEP);
+ int aStepVal = QString::fromStdString(aProp).toInt(&isOk);
+ if (isOk) {
+ mySpinBox->setSingleStep(aStepVal);
+ }
+
+ int aDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk);
+ if (isOk) {
+ mySpinBox->setValue(aDefVal);
+ }
+
+ QString aTTip = QString::fromStdString(theData->widgetTooltip());
+ mySpinBox->setToolTip(aTTip);
+
+ aControlLay->addRow(myLabel, mySpinBox);
+ connect(mySpinBox, SIGNAL(valueChanged(int)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_WidgetIntValue::~ModuleBase_WidgetIntValue()
+{
+}
+
+void ModuleBase_WidgetIntValue::reset()
+{
+ if (isComputedDefault()) {
+ return;
+ //if (myFeature->compute(myAttributeID))
+ // restoreValue();
+ } else {
+ bool isOk;
+ int aDefValue = QString::fromStdString(getDefaultValue()).toInt(&isOk);
+ // reset the value just if there is a default value definition in the XML definition
+ // if the double value can not be found by the default value, do nothing
+ if (isOk) {
+ bool isBlocked = mySpinBox->blockSignals(true);
+ mySpinBox->setValue(isOk ? aDefValue : 0);
+ mySpinBox->blockSignals(isBlocked);
+ storeValueCustom();
+ }
+ }
+}
+
+bool ModuleBase_WidgetIntValue::storeValueCustom() const
+{
+ DataPtr aData = myFeature->data();
+ AttributeIntegerPtr aIntVal = aData->integer(attributeID());
+ int aVal = mySpinBox->value();
+ aIntVal->setValue(mySpinBox->value());
+ updateObject(myFeature);
+ return true;
+}
+
+bool ModuleBase_WidgetIntValue::restoreValue()
+{
+ DataPtr aData = myFeature->data();
+ AttributeIntegerPtr aRef = aData->integer(attributeID());
+ bool isBlocked = mySpinBox->blockSignals(true);
+ mySpinBox->setValue(aRef->value());
+ mySpinBox->blockSignals(isBlocked);
+ return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetIntValue::getControls() const
+{
+ QList<QWidget*> aList;
+ aList.append(mySpinBox);
+ return aList;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetIntValue.h
+// Created: 04 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetIntValue_H
+#define ModuleBase_WidgetIntValue_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QTimer;
+class QSpinBox;
+
+/**
+* \ingroup GUI
+* A class of property panel widget for double value input
+* It can be defined with "doublevalue" keyword. For example:
+* \code
+* <doublevalue id="x" label="X:" icon=":pictures/x_point.png" tooltip="X coordinate"/>
+* \endcode
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetIntValue : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ /// \param theParentId is Id of a parent structure (widget, operation, group)
+ ModuleBase_WidgetIntValue(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+
+ virtual ~ModuleBase_WidgetIntValue();
+
+ /// Fills the widget with default values
+ virtual void reset();
+
+ //! Read value of corresponded attribute from data model to the input control
+ // \return True in success
+ virtual bool restoreValue();
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+
+protected:
+ /// Saves the internal parameters to the given feature
+ /// \return True in success
+ virtual bool storeValueCustom() const;
+
+protected:
+ /// Label of the widget
+ QLabel* myLabel;
+
+ /// Input value control
+ QSpinBox* mySpinBox;
+};
+
+#endif
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_ConstraintFillet.h>
#include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_MultiRotation.h>
+#include <SketchPlugin_MultiTranslation.h>
#include <SketcherPrs_Tools.h>
aIds << SketchPlugin_Point::ID().c_str();
aIds << SketchPlugin_Arc::ID().c_str();
aIds << SketchPlugin_Circle::ID().c_str();
- aIds << SketchPlugin_ConstraintLength::ID().c_str();
- aIds << SketchPlugin_ConstraintDistance::ID().c_str();
- aIds << SketchPlugin_ConstraintRigid::ID().c_str();
- aIds << SketchPlugin_ConstraintRadius::ID().c_str();
- aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
- aIds << SketchPlugin_ConstraintParallel::ID().c_str();
- aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
- aIds << SketchPlugin_ConstraintVertical::ID().c_str();
- aIds << SketchPlugin_ConstraintEqual::ID().c_str();
- aIds << SketchPlugin_ConstraintTangent::ID().c_str();
- aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
aIds << SketchPlugin_ConstraintFillet::ID().c_str();
- aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+ aIds.append(constraintsIdList());
}
return aIds;
}
aIds << SketchPlugin_ConstraintTangent::ID().c_str();
aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+ aIds << SketchPlugin_MultiRotation::ID().c_str();
+ aIds << SketchPlugin_MultiTranslation::ID().c_str();
}
return aIds;
}
{
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeDouble::typeId()/*ModelAPI_AttributeInteger::typeId()*/);
+ data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeInteger::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
AttributeSelectionListPtr aSelection =
void SketchPlugin_MultiRotation::execute()
{
AttributeSelectionListPtr aRotationObjectRefs = selectionList(ROTATION_LIST_ID());
- int aNbCopies = (int)(std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- attribute(NUMBER_OF_COPIES_ID()))->value());
+ int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value();
// Obtain center and angle of rotation
std::shared_ptr<GeomDataAPI_Point2D> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
{
data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeDouble::typeId()/*ModelAPI_AttributeInteger::typeId()*/);
+ data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeInteger::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
AttributeSelectionListPtr aSelection =
void SketchPlugin_MultiTranslation::execute()
{
AttributeSelectionListPtr aTranslationObjectRefs = selectionList(TRANSLATION_LIST_ID());
- int aNbCopies = (int)(std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- attribute(NUMBER_OF_COPIES_ID()))->value());
+ int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value();
// Calculate shift vector
std::shared_ptr<GeomDataAPI_Point2D> aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
title="End point"
tooltip="Final point of translation"/>
</groupbox>
- <doublevalue_editor id="MultiTranslationCopies"
+ <integervalue id="MultiTranslationCopies"
label="Number of copies"
tooltip="Number of copies"
default="1" min="1">
<validator id="GeomValidators_Positive"/>
- </doublevalue_editor>
+ </integervalue>
</feature>
<!-- SketchMultiRotation -->
<feature
id="MultiRotationCenter"
title="Center of rotation"
tooltip="Center of rotation"/>
- <doublevalue_editor id="MultiRotationAngle"
+ <doublevalue id="MultiRotationAngle"
label="Angle"
tooltip="Rotation angle"/>
- <doublevalue_editor id="MultiRotationCopies"
+ <integervalue id="MultiRotationCopies"
label="Number of copies"
tooltip="Number of copies"
default="1" min="1">
<validator id="GeomValidators_Positive"/>
- </doublevalue_editor>
+ </integervalue>
</feature>
</group>
</workbench>
#include <SketchPlugin_MultiRotation.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_ResultConstruction.h>
AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
myNumberOfObjects = anInitialRefList->size();
- myNumberOfCopies = (size_t)std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- aData->attribute(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID()))->value();
+ myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID())->value();
AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (!aRefList) {
if (!theConstraint || theConstraint == myBaseConstraint) {
AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributeDoublePtr aNbCopies = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- myBaseConstraint->attribute(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID()));
- if (anInitialRefList->size() != myNumberOfObjects ||
- (size_t)aNbCopies->value() != myNumberOfCopies) {
+ AttributeIntegerPtr aNbCopies = myBaseConstraint->integer(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID());
+ if (anInitialRefList->size() != myNumberOfObjects || aNbCopies->value() != myNumberOfCopies) {
remove(myBaseConstraint);
process();
return;
#include <SketchPlugin_MultiTranslation.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Data.h>
#include <GeomAPI_Dir2d.h>
#include <GeomAPI_XY.h>
AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
myNumberOfObjects = anInitialRefList->size();
- myNumberOfCopies = (size_t)std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- aData->attribute(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID()))->value();
+ myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID())->value();
AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (!aRefList) {
if (!theConstraint || theConstraint == myBaseConstraint) {
AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributeDoublePtr aNbCopies = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
- myBaseConstraint->attribute(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID()));
+ AttributeIntegerPtr aNbCopies = myBaseConstraint->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID());
if (anInitialRefList->size() != myNumberOfObjects ||
(size_t)aNbCopies->value() != myNumberOfCopies) {
remove(myBaseConstraint);