X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFeature.cpp;h=faf664fe53e9d48180ac7323988e5be4e256808f;hb=94ba553e7b92f11a936e027b49bbd1d501eeee44;hp=6007743f5248434f95cb489e300ac6031a98987d;hpb=975c481c4d5b3c2def28b6674b9c58e47f25ee95;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index 6007743f5..faf664fe5 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -4,78 +4,158 @@ #include +#include +#include +#include + #include #include #include -#include +#include #include #include #include #include +#include +#include +#include +#include #include +#include +#include +#include ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) { - QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE)); - myFeatureKinds = aKinds.split(" "); + myContainer = new QWidget(theParent); + QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); + ModuleBase_Tools::adjustMargins(aControlLay); + + QString aLabelText = QString::fromStdString(theData->widgetLabel()); + myLabel = new QLabel(aLabelText, myContainer); + aControlLay->addWidget(myLabel); + + myEditor = new QLineEdit(myContainer); + QString anObjName = QString::fromStdString(attributeID()); + myEditor->setObjectName(anObjName); + myEditor->setReadOnly(true); + aControlLay->addWidget(myEditor); + + QString aTTip = QString::fromStdString(theData->widgetTooltip()); + myEditor->setToolTip(aTTip); + aControlLay->addWidget(myEditor); + aControlLay->setStretch(1, 1); } ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature() { } -bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature) +bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue) { - if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str())) + bool isDone = false; + + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) + isDone = setObject(aFeatureValue->object()); + } + return isDone; +} + +bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSendEvent) +{ + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + std::list > anArguments; + aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + // Check the type of selected object + std::list::iterator aValidator = aValidators.begin(); + bool isValid = true; + for (; aValidator != aValidators.end(); aValidator++) { + const ModelAPI_ResultValidator* aResValidator = + dynamic_cast(*aValidator); + if (aResValidator) { + isValid = false; + if (aResValidator->isValid(theObject)) { + isValid = true; + break; + } + } + } + if (!isValid) return false; - //bool isBlocked = this->blockSignals(true); - myFeature = theFeature; - //this->blockSignals(isBlocked); - emit valuesChanged(); + // Check the acceptability of the object as attribute + aValidator = aValidators.begin(); + std::list >::iterator aArgs = anArguments.begin(); + for (; aValidator != aValidators.end(); aValidator++, aArgs++) { + const ModelAPI_RefAttrValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theObject)) { + return false; + } + } + } + + myObject = theObject; + myEditor->setText(theObject ? theObject->data()->name().c_str() : ""); + if (theSendEvent) + emit valuesChanged(); return true; } -bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetFeature::storeValue() const { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); + //FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + if (!myObject) + return false; - 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); + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); + ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this; + aRef->setObject(myObject); + myFeature->execute(); + updateObject(myFeature); return true; } -bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetFeature::restoreValue() { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); - - //bool isBlocked = this->blockSignals(true); - myFeature = aRef->feature(); - //this->blockSignals(isBlocked); - return true; + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); + + ObjectPtr anObjPtr = aRef->object(); + if (anObjPtr) { + myObject = anObjPtr; + myEditor->setText(myObject ? myObject->data()->name().c_str() : ""); + return true; + } + return false; } QWidget* ModuleBase_WidgetFeature::getControl() const { - return 0; + return myContainer; } QList ModuleBase_WidgetFeature::getControls() const { - QList aControls; - return aControls; + QList aList; + aList.append(myLabel); + aList.append(myEditor); + return aList; }