Distance between line points.
const static char* WDG_POINT2D_DISTANCE = "point2ddistance";
const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+const static char* WDG_FEATURE_OR_ATTRIBUTE_SELECTOR = "feature_or_attribute_selector";
const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
const static char* _ID = "id";
ModuleBase_WidgetEditor.h
ModuleBase_WidgetFactory.h
ModuleBase_WidgetFeature.h
+ ModuleBase_WidgetFeatureOrAttribute.h
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
ModuleBase_WidgetSelector.h
ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetFactory.cpp
ModuleBase_WidgetFeature.cpp
+ ModuleBase_WidgetFeatureOrAttribute.cpp
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetSelector.cpp
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetFeatureOrAttribute.h>
#include <ModuleBase_WidgetFeature.h>
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_WidgetSwitch.h>
} else if (theType == WDG_FEATURE_SELECTOR) {
result = featureSelectorControl(theParent);
+ } else if (theType == WDG_FEATURE_OR_ATTRIBUTE_SELECTOR) {
+ result = featureOrAttributeSelectorControl(theParent);
+
} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
result = doubleValueEditor(theParent);
return aWidget->getControl();
}
+QWidget* ModuleBase_WidgetFactory::featureOrAttributeSelectorControl(QWidget* theParent)
+{
+ ModuleBase_WidgetFeatureOrAttribute* aWidget = new ModuleBase_WidgetFeatureOrAttribute(theParent,
+ myWidgetApi);
+ myModelWidgets.append(aWidget);
+ return aWidget->getControl();
+}
+
QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
{
ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi);
QWidget* doubleSpinBoxControl(QWidget* theParent);
QWidget* pointSelectorControl(QWidget* theParent);
QWidget* featureSelectorControl(QWidget* theParent);
+ QWidget* featureOrAttributeSelectorControl(QWidget* theParent);
QWidget* doubleValueEditor(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
QWidget* selectorControl(QWidget* theParent);
protected:
/// Fill the widget values by given point
/// \param thePoint the point
+ /// \return the boolean result of the feature set
bool setFeature(const FeaturePtr& theFeature);
+ /// Returns current widget feature
+ /// \return the feature
+ const FeaturePtr& feature() const { return myFeature; }
+
+ /// Returns the widget editor
+ /// \return the editor
+ QLineEdit* editor() const { return myEditor; }
+
+ /// Returns the possible feature kinds
+ /// \return the list of kinds
+ const QStringList& featureKinds() const { return myFeatureKinds; }
+
private:
FeaturePtr myFeature; ///< the current widget feature
QStringList myFeatureKinds; ///< the kinds of possible features
--- /dev/null
+// File: ModuleBase_WidgetFeatureOrAttribute.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetFeatureOrAttribute.h>
+
+#include <ModuleBase_WidgetValueFeature.h>
+#include <ModuleBase_WidgetValue.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <Precision.hxx>
+
+#include <QWidget>
+#include <QLineEdit>
+#include <QHBoxLayout>
+#include <QLabel>
+
+ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+: ModuleBase_WidgetFeature(theParent, theData)
+{
+}
+
+ModuleBase_WidgetFeatureOrAttribute::~ModuleBase_WidgetFeatureOrAttribute()
+{
+}
+
+bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theValue)
+{
+ bool isDone = false;
+
+ if (theValue) {
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (aFeatureValue) {
+ boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
+ FeaturePtr aValueFeature = aFeatureValue->feature();
+
+ if (aValueFeature) {
+ isDone = setFeature(aValueFeature);
+ }
+ if (!isDone) {
+ // find the given point in the feature attributes
+ std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
+ aValueFeature->data()->attributes(GeomDataAPI_Point2D::type());
+ std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
+ aLast = anAttiributes.end();
+ boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+ for (;anIt!=aLast && !aFPoint; anIt++) {
+ boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
+ aFPoint = aCurPoint;
+ }
+ if (aFPoint)
+ isDone = setAttribute(aFPoint);
+ }
+ }
+ }
+ return isDone;
+}
+
+bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) const
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
+
+ ModuleBase_WidgetFeatureOrAttribute* that = (ModuleBase_WidgetFeatureOrAttribute*) this;
+ if (feature())
+ aRef->setFeature(feature());
+ else if (myAttribute)
+ aRef->setAttr(myAttribute);
+
+ theFeature->execute();
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+
+ return true;
+}
+
+bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
+
+ FeaturePtr aFeature = aRef->feature();
+ setFeature(aFeature);
+ myAttribute = aRef->attr();
+
+ std::string aText = "";
+ if (aFeature)
+ aText = aFeature->data()->getName().c_str();
+ else if (myAttribute)
+ aText = myAttribute->attributeType().c_str();
+
+ editor()->setText(aText.c_str());
+ return true;
+}
+
+bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr<ModelAPI_Attribute>& theAttribute)
+{
+ if (!theAttribute || !featureKinds().contains(theAttribute->attributeType().c_str()))
+ return false;
+
+ myAttribute = theAttribute;
+ editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : "");
+ emit valuesChanged();
+ return true;
+}
+
--- /dev/null
+// File: ModuleBase_WidgetFeatureOrAttribute.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetFeatureOrAttribute_H
+#define ModuleBase_WidgetFeatureOrAttribute_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_WidgetFeature.h"
+
+#include <QObject>
+
+class ModuleBase_WidgetValue;
+class ModelAPI_Attribute;
+
+/**\class ModuleBase_WidgetFeatureOrAttribute
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetFeatureOrAttribute : public ModuleBase_WidgetFeature
+{
+ Q_OBJECT
+public:
+ /// Constructor
+ /// \theParent the parent object
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, const Config_WidgetAPI* theData);
+ /// Destructor
+ virtual ~ModuleBase_WidgetFeatureOrAttribute();
+
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// \param theValue the wrapped widget value
+ virtual bool setValue(ModuleBase_WidgetValue* theValue);
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+protected:
+ /// Set the attribute
+ /// \param theAttribute value
+ /// \return the boolean result of the attribute set
+ bool setAttribute(const boost::shared_ptr<ModelAPI_Attribute>& theAttribute);
+
+protected:
+ boost::shared_ptr<ModelAPI_Attribute> myAttribute; /// < the attribute
+};
+
+#endif
{
boost::shared_ptr<ModelAPI_Data> aData = data();
- boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_A =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
-
- AttributeDoublePtr anAttr_Value =
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A);
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B);
+ if (aPoint_A && aPoint_B) {
+ AttributeDoublePtr anAttr_Value =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
- if (anAttr_A->isInitialized() && anAttr_B->isInitialized() && !anAttr_Value->isInitialized())
- {
- FeaturePtr aFeature_A = anAttr_A->feature();
- FeaturePtr aFeature_B = anAttr_B->feature();
- if (aFeature_A && aFeature_A) {
- // calculate the distance
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aFeature_A->data()->attribute(POINT_ATTR_COORD));
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aFeature_B->data()->attribute(POINT_ATTR_COORD));
- if (aPoint_A && aPoint_B) {
- anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
- }
+
+ if (!anAttr_Value->isInitialized()) {
+ anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
}
}
}
if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND)
aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aFeature->data()->attribute(POINT_ATTR_COORD));
+ else {
+ if (anAttr->attr())
+ aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
return aPointAttr;
}
-
<feature id="SketchConstraintCoincidence" title="Coincident" tooltip="Create constraint for the coincidence of two points" internal="1"/>
<feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object">
<label title="Select point and another feature (point or point on line) between which to calculate distance" tooltip="Select point and another feature (point or point on line) between which to calculate distance"/>
- <feature_selector id="ConstraintEntityA" label="First point" tooltip="Select an point in the viewer" keysequence="SketchPoint"/>
- <feature_selector id="ConstraintEntityB" label="Last point" tooltip="Select an point in the viewer" keysequence="SketchPoint"/>
+ <feature_or_attribute_selector id="ConstraintEntityA" label="First point" tooltip="Select an point in the viewer" keysequence="SketchPoint Point2D"/>
+ <feature_or_attribute_selector id="ConstraintEntityB" label="Last point" tooltip="Select an point in the viewer" keysequence="SketchPoint Point2D"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
</feature>