//Specific widget containers
const static char* WDG_POINT_SELECTOR = "point_selector";
+const static char* WDG_POINT2D_DISTANCE = "point2ddistance";
const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
const static char* _ID = "id";
//const static char* WORKBENCH_ID = "id";
const static char* FEATURE_INTERNAL = "internal";
const static char* SOURCE_FILE = "path";
+const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
// doublevalue properties:
const static char* INFO_WDG_TEXT = FEATURE_TEXT;
#include "GeomData_Dir.h"
#include "GeomAPI_Dir.h"
#include <gp_Dir.hxx>
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
{
- if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY ||
+ myCoords->Value(2) != theZ) {
myCoords->SetValue(0, theX);
myCoords->SetValue(1, theY);
myCoords->SetValue(2, theZ);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Dir::setValue(const boost::shared_ptr<GeomAPI_Dir>& theDir)
{
setValue(theDir->x(), theDir->y(), theDir->z());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Dir::x() const
GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
}
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
#include <GeomAPI_Pnt.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
{
- if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY ||
+ myCoords->Value(2) != theZ) {
myCoords->SetValue(0, theX);
myCoords->SetValue(1, theY);
myCoords->SetValue(2, theZ);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Point::setValue(const boost::shared_ptr<GeomAPI_Pnt>& thePoint)
{
setValue(thePoint->x(), thePoint->y(), thePoint->z());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Point::x() const
GeomData_Point::GeomData_Point(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
}
// Author: Mikhail PONIKAROV
#include "GeomData_Point2D.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
#include <GeomAPI_Pnt2d.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
if (myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
myCoords->SetValue(0, theX);
myCoords->SetValue(1, theY);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Point2D::setValue(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
{
setValue(thePoint->x(), thePoint->y());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Point2D::x() const
GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
}
// Author: Vitaly Smetannikov
#include "Model_AttributeBoolean.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeBoolean::setValue(bool theValue)
{
Standard_Boolean aValue = theValue ? Standard_True : Standard_False;
- if (myBool->Get() != aValue) {
+ if (!myIsInitialized || myBool->Get() != aValue) {
myBool->Set(aValue);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
{
// check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myBool = TDataStd_Integer::Set(theLabel, 0);
}
#include "Model_AttributeDocRef.h"
#include "Model_Application.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
{
TCollection_ExtendedString aNewID(theDoc->id().c_str());
- if (myComment->Get() != aNewID) {
+ if (!myIsInitialized || myComment->Get() != aNewID) {
myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just empty string
myComment = TDataStd_Comment::Set(theLabel, "");
} else { // document was already referenced: try to set it as loaded by demand
// Author: Mikhail PONIKAROV
#include "Model_AttributeDouble.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeDouble::setValue(const double theValue)
{
- if (myReal->Get() != theValue) {
+ if (!myIsInitialized || myReal->Get() != theValue) {
myReal->Set(theValue);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
{
// check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myReal = TDataStd_Real::Set(theLabel, 0.);
}
#include "Model_AttributeRefAttr.h"
#include "Model_Application.h"
-#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
using namespace std;
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theAttr->owner()->data());
string anID = aData->id(theAttr);
- if (feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
+ if (myIsInitialized && feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
return; // nothing is changed
myRef->Set(aData->label());
myID->Set(aData->id(theAttr).c_str());
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature)
{
- if (myID->Get().Length() != 0 || feature() != theFeature) {
+ if (!myIsInitialized || myID->Get().Length() != 0 || feature() != theFeature) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Set(aData->label());
myID->Set(""); // feature is identified by the empty ID
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myID)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet
myID = TDataStd_Comment::Set(theLabel, "");
myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself
#include "Model_AttributeRefList.h"
#include "Model_Application.h"
-#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
#include <TDF_ListIteratorOfLabelList.hxx>
using namespace std;
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Append(aData->label());
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
void Model_AttributeRefList::remove(FeaturePtr theFeature)
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Remove(aData->label());
+ owner()->data()->sendAttributeUpdated(this);
}
int Model_AttributeRefList::size()
Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
+ if (!myIsInitialized) {
myRef = TDataStd_ReferenceList::Set(theLabel);
}
}
#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
using namespace std;
void Model_AttributeReference::setValue(FeaturePtr theFeature)
{
- if (value() != theFeature) {
+ if (!myIsInitialized || value() != theFeature) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
if (myRef.IsNull()) {
} else {
myRef->Set(aData->label());
}
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDF_Reference::GetID(), myRef)) {
- // create attribute: not initialized by value yet: attribute is not set to the label!
- }
+ // not initialized by value yet: attribute is not set to the label!
+ myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
}
return !myLab.IsNull() && myLab.HasAttribute();
}
+list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const string theType)
+{
+ list<boost::shared_ptr<ModelAPI_Attribute> > aResult;
+ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = myAttrs.begin();
+ for(; anAttrsIter != myAttrs.end(); anAttrsIter++) {
+ if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
+ }
+ }
+ return aResult;
+}
+
+void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
+{
+ theAttr->setInitialized();
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
+ Events_Loop::loop()->send(aMsg);
+}
+
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TopoDS_Shape.hxx>
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
+ /// Returns all attributes ofthe feature of the given type
+ /// or all attributes if "theType" is empty
+ MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
+ attributes(const std::string theType);
+
/// Identifier by the id (not fast, iteration by map)
/// \param theAttr attribute already created in this data
MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr);
/// \param theAttrType type of the created attribute (received from the type method)
MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
+ /// Useful method for "set" methods of the attributes: sends an UPDATE event and
+ /// makes attribute initialized
+ MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
+
/// Puts feature to the document data sub-structure
MODEL_EXPORT void setLabel(TDF_Label& theLab);
{
///< needed here to emit signal that feature changed on change of the attribute
boost::shared_ptr<ModelAPI_Feature> myFeature;
+protected: // accessible from the attributes
+ bool myIsInitialized;
public:
/// Returns the type of this class of attributes, not static method
/// Returns the owner of this attribute
MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Feature>& owner()
{return myFeature;}
+
+ /// Returns true if attribute was initialized by some value
+ MODELAPI_EXPORT bool isInitialized() {return myIsInitialized;}
+
+ /// Makes attribute initialized
+ MODELAPI_EXPORT void setInitialized() {myIsInitialized = true;}
+
protected:
/// Objects are created for features automatically
- ModelAPI_Attribute(){}
+ ModelAPI_Attribute() {myIsInitialized = false;}
};
#include "ModelAPI.h"
#include <string>
+#include <list>
#include <boost/shared_ptr.hpp>
class ModelAPI_AttributeDocRef;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+ /// Returns all attributes ofthe feature of the given type
+ /// or all attributes if "theType" is empty
+ virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
+ attributes(const std::string theType) = 0;
/// Identifier by the id (not fast, iteration by map)
/// \param theAttr attribute already created in this data
virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
/// \param theAttrType type of the created attribute (received from the type method)
virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
+ /// Useful method for "set" methods of the attributes: sends an UPDATE event and
+ /// makes attribute initialized
+ virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
+
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Data() {}
ModuleBase_ModelWidget.h
ModuleBase_WidgetBoolValue.h
ModuleBase_WidgetDoubleValue.h
+ ModuleBase_WidgetEditor.h
ModuleBase_WidgetFactory.h
ModuleBase_WidgetFeature.h
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
ModuleBase_WidgetSelector.h
ModuleBase_IWorkshop.h
+ ModuleBase_WidgetPoint2dDistance.h
)
SET(PROJECT_SOURCES
ModuleBase_ModelWidget.cpp
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetDoubleValue.cpp
+ ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetFactory.cpp
ModuleBase_WidgetFeature.cpp
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetSelector.cpp
+ ModuleBase_WidgetPoint2dDistance.cpp
)
SET(PROJECT_LIBRARIES
Config
ModelAPI
+ GeomAPI
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
/// \param theAttributeName a name of the attribute
/// \param theEvent key release event
void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
+ /// The signal about the widget is lost focus
+ /// \param theWidget the model base widget
+ void focusOutWidget(ModuleBase_ModelWidget* theWidget);
protected:
bool myHasDefaultValue; /// the boolean state whether the control has a default value
/// \param theEvent the processed event
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
-private:
+protected:
QWidget* myContainer;
QLabel* myLabel;
QDoubleSpinBox* mySpinBox;
--- /dev/null
+// File: ModuleBase_WidgetEditor.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetEditor.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_AttributeDouble.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <QWidget>
+#include <QLineEdit>
+
+ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+ 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;
+}
+
+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);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ //that->blockSignals(isBlocked);
+ }
+ return true;
+}
+
+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);
+ return true;
+}
+
+void ModuleBase_WidgetEditor::focusTo()
+{
+ QPoint aPoint = QCursor::pos();
+
+ myEditor->move(aPoint);
+ myEditor->show();
+
+ myEditor->selectAll();
+ myEditor->setFocus();
+}
+
+QWidget* ModuleBase_WidgetEditor::getControl() const
+{
+ return 0;
+}
+
+QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
+{
+ QList<QWidget*> aControls;
+ return aControls;
+}
+
+void ModuleBase_WidgetEditor::onStopEditing()
+{
+ myEditor->hide();
+ emit focusOutWidget(this);
+}
--- /dev/null
+// File: ModuleBase_WidgetEditor.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetEditor_H
+#define ModuleBase_WidgetEditor_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_ModelWidget.h"
+
+#include <QObject>
+#include <QStringList>
+
+class ModelAPI_Feature;
+class QLineEdit;
+
+/**\class ModuleBase_WidgetEditor
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetEditor : 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_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData);
+ /// Destructor
+ virtual ~ModuleBase_WidgetEditor();
+
+ /// 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);
+
+ /// Set focus to the first control of the current widget. The focus policy of the control is checked.
+ /// If the widget has the NonFocus focus policy, it is skipped.
+ virtual void focusTo();
+
+ /// 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;
+
+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
+};
+
+#endif
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetFeature.h>
+#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_WidgetSwitch.h>
#include <ModuleBase_WidgetSelector.h>
#include <ModuleBase_WidgetDoubleValue.h>
#include <ModuleBase_WidgetBoolValue.h>
+#include <ModuleBase_WidgetPoint2dDistance.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
//Create a widget (doublevalue, groupbox, toolbox, etc.
QWidget* aWidget = createWidgetByType(aWdgType, theParent);
if (aWidget) {
- aWidgetLay->addWidget(aWidget);
+ if (!isInternalWidget(aWdgType)) {
+ aWidgetLay->addWidget(aWidget);
+ }
+ else
+ aWidget->setVisible(false);
}
if (myWidgetApi->isContainerWidget()) {
//if current widget is groupbox (container) process it's children recursively
} else if (theType == WDG_FEATURE_SELECTOR) {
result = featureSelectorControl(theParent);
+ } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
+ result = doubleValueEditor(theParent);
+
+ } else if (theType == WDG_POINT2D_DISTANCE) {
+ result = point2dDistanceControl(theParent);
+
}
else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
return aWidget->getControl();
}
+QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
+{
+ ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi);
+ myModelWidgets.append(aWidget);
+ return 0;
+}
+
QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
{
return QString::fromStdString(theStdString);
}
+bool ModuleBase_WidgetFactory::isInternalWidget(const std::string& theType)
+{
+ std::string prop = myWidgetApi->getProperty(FEATURE_INTERNAL);
+
+ std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
+ if(prop.empty() || prop == "false" || prop == "0") {
+ return false;
+ }
+ return true;
+}
QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
{
myModelWidgets.append(aBoolWgt);
return aBoolWgt->getControl();
+}
+
+
+QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent)
+{
+ ModuleBase_WidgetPoint2dDistance* aDistWgt = new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi);
+ myModelWidgets.append(aDistWgt);
+
+ return aDistWgt->getControl();
}
\ No newline at end of file
QWidget* doubleSpinBoxControl(QWidget* theParent);
QWidget* pointSelectorControl(QWidget* theParent);
QWidget* featureSelectorControl(QWidget* theParent);
+ QWidget* doubleValueEditor(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
QWidget* selectorControl(QWidget* theParent);
QWidget* booleanControl(QWidget* theParent);
+ QWidget* point2dDistanceControl(QWidget* theParent);
+
+ /// Check whether the XML definition for the given type contains internal property
+ /// \param theType the widget type
+ /// \return the boolean result
+ bool isInternalWidget(const std::string& theType);
QString qs(const std::string& theStdString) const;
ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
//bool isBlocked = that->blockSignals(true);
aRef->setFeature(myFeature);
+ theFeature->execute();
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
//that->blockSignals(isBlocked);
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData)
{
+ myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
theParent);
QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
{
+
bool isBlocked = this->blockSignals(true);
myXSpin->setValue(thePoint->x());
myYSpin->setValue(thePoint->y());
}
return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
}
+
+void ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature)
+{
+ if (myOptionParam.length() == 0)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myOptionParam));
+ if (aPoint) {
+ bool isBlocked = this->blockSignals(true);
+ myXSpin->setValue(aPoint->x());
+ this->blockSignals(isBlocked);
+ myYSpin->setValue(aPoint->y());
+ }
+}
/// \param theEvent the processed event
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+ void initFromPrevious(FeaturePtr theFeature);
+
private:
QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate
QDoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate
+
+ std::string myOptionParam; /// Parameter name which has to be taken from previous feature
};
#endif
--- /dev/null
+// File: ModuleBase_WidgetPoint2dDistance.h
+// Created: 23 June 2014
+// Author: Vitaly Smetannikov
+
+#include "ModuleBase_WidgetPoint2dDistance.h"
+
+#include <GeomAPI_Pnt2d.h>
+#include <Config_WidgetAPI.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <QDoubleSpinBox>
+
+ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData)
+ : ModuleBase_WidgetDoubleValue(theParent, theData)
+{
+ myFirstPntName = theData->getProperty("first_point");
+}
+
+ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance()
+{
+}
+
+void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(myFirstPntName));
+ double aRadius = thePnt->distance(aPoint->pnt());
+ AttributeDoublePtr aReal = aData->real(attributeID());
+ if (aReal && (aReal->value() != aRadius)) {
+ aReal->setValue(aRadius);
+ mySpinBox->setValue(aRadius);
+ }
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_WidgetPoint2dDistance.h
+// Created: 23 June 2014
+// Author: Vitaly Smetannikov
+
+
+#ifndef ModuleBase_WidgetPoint2dDistance_H
+#define ModuleBase_WidgetPoint2dDistance_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_WidgetDoubleValue.h"
+
+class GeomAPI_Pnt2d;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance: public ModuleBase_WidgetDoubleValue
+{
+ Q_OBJECT
+public:
+ /// Constructor
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_WidgetPoint2dDistance();
+
+ /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
+ void setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt);
+
+private:
+ std::string myFirstPntName;
+};
+
+
+#endif
\ No newline at end of file
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetFeature.h>
+#include <ModuleBase_WidgetPoint2dDistance.h>
#include <XGUI_ViewerPrs.h>
#include <XGUI_Constants.h>
bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
{
- return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*||
- theId == SKETCH_CONSTRAINT_DISTANCE_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*/;
}
myActiveWidget = theWidget;
if (myInitFeature && myActiveWidget) {
- // TODO: to be realized in the custom point selector. The last point values of the init feature
- // should be to to the start point of a new feature
- //myActiveWidget->init(myInitFeature);
- //PartSet_FeatureLinePrs::setFeature(myInitFeature, SM_FirstPoint);
+ ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
+ if (aWgt)
+ aWgt->initFromPrevious(myInitFeature);
myInitFeature = FeaturePtr();
emit activateNextWidget(myActiveWidget);
}
bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
{
+ boost::shared_ptr<GeomAPI_Pnt2d> aPoint(new GeomAPI_Pnt2d(theX, 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)));
- return true;
+ if (aWidget) {
+ aWidget->setPoint(aPoint);
+ return true;
+ } else {
+ ModuleBase_WidgetPoint2dDistance* aWgt = dynamic_cast<ModuleBase_WidgetPoint2dDistance*>(myActiveWidget);
+ if (aWgt) {
+ aWgt->setPoint(feature(), aPoint);
+ return true;
+ }
+ }
+ return false;
}
bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature)
void SketchPlugin_ConstraintDistance::execute()
{
+ 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 anAttribute =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+
+ if (anAttr_A && anAttr_B && anAttribute->value() == 0)
+ {
+ FeaturePtr aFeature_A = anAttr_A->feature();
+ FeaturePtr aFeature_B = anAttr_B->feature();
+
+ double aValue = 40; // TODO
+ anAttribute->setValue(aValue);
+ }
}
Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
<point_selector id="PointCoordindates" title="Point" tooltip="Point"/>
</feature>
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
- <point_selector id="StartPoint" title="Start point" tooltip="Start point of the line"/>
+ <point_selector id="StartPoint" title="Start point" tooltip="Start point of the line" previous_feature_param="EndPoint"/>
<point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>
</feature>
<feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon="">
<point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
- <doublevalue id="CircleRadius" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
+ <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
</feature>
<feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon="">
<point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>
<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_selector id="ConstraintEntityA" keysequence="SketchPoint" internal="1"/>
+ <feature_selector id="ConstraintEntityB" keysequence="SketchPoint" internal="1"/>
+ <point_selector id="ConstraintFlyoutValuePnt" title="Flyout point" tooltip="Flyout" internal="1"/>
+ <doublevalue_editor id="ConstraintValue" min="0" step="1.0" 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"/>
for (; anIt != aLast; anIt++) {
connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
+
+ connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
+ this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
}
ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
if (aLastWidget) {