Widget controls for a constraint filling.
Config_XMLReader.h
Config_ModuleReader.h
Config_FeatureReader.h
+ Config_Keywords.h
Config_WidgetAPI.h
Config_WidgetReader.h
Config_PointerMessage.h
//Specific widget containers
const static char* WDG_POINT_SELECTOR = "point_selector";
+const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+
const static char* _ID = "id";
//const static char* WORKBENCH_ID = "id";
//const static char* GROUP_ID = "id";
ModuleBase_WidgetBoolValue.h
ModuleBase_WidgetDoubleValue.h
ModuleBase_WidgetFactory.h
+ ModuleBase_WidgetFeature.h
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
ModuleBase_WidgetSelector.h
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetDoubleValue.cpp
ModuleBase_WidgetFactory.cpp
+ ModuleBase_WidgetFeature.cpp
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetSelector.cpp
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetFeature.h>
#include <ModuleBase_WidgetSwitch.h>
#include <ModuleBase_WidgetSelector.h>
#include <ModuleBase_WidgetDoubleValue.h>
} else if (theType == WDG_POINT_SELECTOR) {
result = pointSelectorControl(theParent);
- } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
+ } else if (theType == WDG_FEATURE_SELECTOR) {
+ result = featureSelectorControl(theParent);
+
+ }
+ else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
}
#ifdef _DEBUG
return aWidget->getControl();
}
+QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent)
+{
+ ModuleBase_WidgetFeature* aWidget = new ModuleBase_WidgetFeature(theParent, myWidgetApi);
+ myModelWidgets.append(aWidget);
+ return aWidget->getControl();
+}
+
QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
{
return QString::fromStdString(theStdString);
QWidget* labelControl(QWidget* theParent);
QWidget* doubleSpinBoxControl(QWidget* theParent);
QWidget* pointSelectorControl(QWidget* theParent);
+ QWidget* featureSelectorControl(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
QWidget* selectorControl(QWidget* theParent);
QWidget* booleanControl(QWidget* theParent);
--- /dev/null
+// File: ModuleBase_WidgetFeature.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetFeature.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 <QWidget>
+
+ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+ QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
+ myFeatureKinds = aKinds.split(" ");
+}
+
+ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
+{
+}
+
+bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
+{
+ if (!theFeature && myFeatureKinds.contains(theFeature->getKind().c_str()))
+ return false;
+
+ //bool isBlocked = this->blockSignals(true);
+ myFeature = theFeature;
+ //this->blockSignals(isBlocked);
+ emit valuesChanged();
+ return true;
+}
+
+bool ModuleBase_WidgetFeature::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_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
+ //bool isBlocked = that->blockSignals(true);
+ aRef->setFeature(myFeature);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ //that->blockSignals(isBlocked);
+
+ return true;
+}
+
+bool ModuleBase_WidgetFeature::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()));
+
+ //bool isBlocked = this->blockSignals(true);
+ myFeature = aRef->feature();
+ //this->blockSignals(isBlocked);
+ return true;
+}
+
+QWidget* ModuleBase_WidgetFeature::getControl() const
+{
+ return 0;
+}
+
+QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
+{
+ QList<QWidget*> aControls;
+ return aControls;
+}
--- /dev/null
+// File: ModuleBase_WidgetFeature.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetFeature_H
+#define ModuleBase_WidgetFeature_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_ModelWidget.h"
+
+#include <QObject>
+#include <QStringList>
+
+class ModelAPI_Feature;
+
+/**\class ModuleBase_WidgetFeature
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetFeature : public ModuleBase_ModelWidget
+{
+ 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_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData);
+ /// Destructor
+ virtual ~ModuleBase_WidgetFeature();
+
+ /// Fill the widget values by given point
+ /// \param thePoint the point
+ bool setFeature(const FeaturePtr& theFeature);
+
+ /// 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);
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const;
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+private:
+ FeaturePtr myFeature; ///< the current widget feature
+ QStringList myFeatureKinds; ///< the kinds of possible features
+};
+
+#endif
switch (theMode)
{
case SM_LastPoint: {
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(feature(),
- CONSTRAINT_ATTR_ENTITY_A);
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(feature(),
- CONSTRAINT_ATTR_ENTITY_B);
-
- boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
- (new GeomAPI_Pnt2d(theX, theY));
- boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
- (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
- aPoint_B->x(), aPoint_B->y()));
- boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
- double aDistance = aPoint->distance(aResult);
-
- if (!aFeatureLin->isRight(aPoint))
- aDistance = -aDistance;
-
- AttributeDoublePtr aFlyoutAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>
- (feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
- aFlyoutAttr->setValue(aDistance);
+ boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ aFlyOutAttr->setValue(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+
+ boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
aMode = SM_DonePoint;
}
if (!aPoint_A || !aPoint_B)
return anAIS;
+ // fly out calculation
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- 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<GeomDataAPI_Point2D> aFlyOutAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
- boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
- double aValue = aValueAttr->value();
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+ (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
+ aPoint_B->x(), aPoint_B->y()));
+ boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aFlyOutPnt);
+ double aDistance = aFlyOutPnt->distance(aResult);
+
+ if (!aFeatureLin->isRight(aFlyOutPnt))
+ aDistance = -aDistance;
+ double aFlyout = aDistance;
gp_Pnt aPoint1, aPoint2;
PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1);
aP2 = aPoint1;
}
+ // value calculation
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ double aValue = aValueAttr->value();
+ if (aValue == 0) { // TODO! the default value
+ aValue = aP1.Distance(aP2);
+ }
+
if (anAIS.IsNull())
{
Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane);
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_ConstraintDistance.h>
#include <GeomAPI_Pnt2d.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetFeature.h>
#include <XGUI_ViewerPrs.h>
#include <XGUI_Constants.h>
PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ FeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myActiveWidget(0)
{
}
bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
{
- return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*|| theId == SKETCH_CIRCLE_KIND ||
+ return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*||
+ theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND ||
theId == SKETCH_ARC_KIND*/;
}
anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
}
}*/
- setWidgetPoint(aX, anY);
+ bool isApplyed = false;
+ if (isPointWidget())
+ isApplyed = setWidgetPoint(aX, anY);
+ else {
+ if (!theSelected.empty()) {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ FeaturePtr aFeature = aPrs.feature();
+ if (aFeature)
+ isApplyed = setWidgetFeature(aFeature);
+ }
+ }
flushUpdated();
emit activateNextWidget(myActiveWidget);
}
}
}*/
-void PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
+bool PartSet_OperationFeatureCreate::isPointWidget() const
+{
+ return dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
+}
+
+bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
{
ModuleBase_WidgetPoint2D* aWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
+ if (!aWidget)
+ return false;
+
aWidget->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
-}
\ No newline at end of file
+ return true;
+}
+
+bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature)
+{
+ ModuleBase_WidgetFeature* aWidget = dynamic_cast<ModuleBase_WidgetFeature*>(myActiveWidget);
+ if (!aWidget)
+ return false;
+
+ return aWidget->setFeature(theFeature);
+}
//void setPointSelectionMode(const PartSet_SelectionMode& theMode,
// const bool isToEmitSignal = true);
- /// Set the widget point
+ /// Returns true if the active widget is the point selector widget
+ /// \return the boolean value
+ bool isPointWidget() const;
+
+ /// Set the point to the active widget
/// \param theX the horizontal coordinate
/// \param theY the vertical coordinate
- void setWidgetPoint(double theX, double theY);
+ /// \return true if the point is set
+ bool setWidgetPoint(double theX, double theY);
+
+ /// Set the feature to the active widget
+ /// \param theFeature a feature
+ /// \return true if the feature is set
+ bool setWidgetFeature(const FeaturePtr& theFeature);
private:
//boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
*/
/// The value parameter for the constraint
const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue");
+/// The 2D value parameter for the constraint
+const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
/// The value parameter for the constraint
const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue");
/// First entity for the constraint
#include "SketchPlugin_ConstraintDistance.h"
+#include "GeomDataAPI_Point2D.h"
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <SketchPlugin_Point.h>
void SketchPlugin_ConstraintDistance::initAttributes()
{
data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type());
- data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
+ data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
}
<feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
<feature id="SketchConstraintDistance" title="Distance between objects" 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" keysequence="SketchPoint"/>
+ <feature_selector id="ConstraintEntityB" keysequence="SketchPoint"/>
+ <point_selector id="ConstraintFlyoutValuePnt" title="Flyout point" tooltip="Flyout"/>
+ <doublevalue id="ConstraintValue" label="Value:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Constraint value"/>
</feature>
<feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
<label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>