#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_IViewer.h>
#include<ModuleBase_FilterFactory.h>
+#include <ModuleBase_PageBase.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
aMsg->parameters());
}
}
- }
-
-
- else {
+ } else {
//Show error dialog if error message received.
std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
if (anAppError) {
emit errorOccurred(QString::fromLatin1(anAppError->description()));
}
+ return;
}
if (!isSalomeMode()) {
SessionPtr aMgr = ModelAPI_Session::get();
myPropertyPanel->cleanContent();
aFactory.createWidget(myPropertyPanel->contentWidget());
- ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
bool isStoreValue = !theOperation->isEditOperation() &&
- !aWidget->getDefaultValue().empty() && !aWidget->isComputedDefault();
+ !aWidget->getDefaultValue().empty() &&
+ !aWidget->isComputedDefault();
aWidget->setFeature(theOperation->feature(), isStoreValue);
aWidget->enableFocusProcessing();
}
activatePart(ResultPartPtr());
else if (theId == "DELETE_CMD")
deleteObjects(aObjects);
+ else if (theId == "COLOR_CMD")
+ changeColor(aObjects);
else if (theId == "SHOW_CMD")
showObjects(aObjects, true);
else if (theId == "HIDE_CMD")
//**************************************************************
void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
{
- QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
+ ModuleBase_IModule* aModule = module();
+ if (aModule->deleteObjects())
+ return;
+ if (!isActiveOperationAborted())
+ return;
+
+ QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
std::set<FeaturePtr> aRefFeatures;
foreach (ObjectPtr aObj, theList)
{
return;
}
- SessionPtr aMgr = ModelAPI_Session::get();
QString aDescription = tr("Delete %1");
QStringList aObjectNames;
foreach (ObjectPtr aObj, theList) {
aObjectNames << QString::fromStdString(aObj->data()->name());
}
aDescription = aDescription.arg(aObjectNames.join(", "));
+ SessionPtr aMgr = ModelAPI_Session::get();
aMgr->startOperation(aDescription.toStdString());
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
updateCommandStatus();
}
+bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
+{
+ bool isFoundResultType = false;
+ foreach(ObjectPtr anObj, theObjects)
+ {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() == NULL)
+ continue;
+
+ isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
+ if (isFoundResultType)
+ break;
+ }
+ return isFoundResultType;
+}
+
+//**************************************************************
+bool XGUI_Workshop::canChangeColor() const
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+
+ std::set<std::string> aTypes;
+ aTypes.insert(ModelAPI_ResultGroup::group());
+ aTypes.insert(ModelAPI_ResultConstruction::group());
+ aTypes.insert(ModelAPI_ResultBody::group());
+ return hasResults(aObjects, aTypes);
+}
+
+//**************************************************************
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QtxColorButton.h>
+#include <ModelAPI_AttributeColor.h>
+void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+{
+ // 1. find the initial value of the color
+ AttributeColorPtr aColorAttr;
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL)
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ }
+ }
+ // there is no object with the color attribute
+ if (aColorAttr.get() == NULL)
+ return;
+ int aRed, aGreen, aBlue;
+ aColorAttr->values(aRed, aGreen, aBlue);
+
+ // 2. show the dialog to change the value
+ QDialog* aDlg = new QDialog();
+ QVBoxLayout* aLay = new QVBoxLayout(aDlg);
+
+ QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
+ aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ aLay->addWidget(aColorBtn);
+ aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+
+ QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, aDlg);
+ connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
+ connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
+ aLay->addWidget(aButtons);
+
+ aDlg->move(QCursor::pos());
+ bool isDone = aDlg->exec() == QDialog::Accepted;
+ if (!isDone)
+ return;
+
+ QColor aColorResult = aColorBtn->color();
+ int aRedResult = aColorResult.red(),
+ aGreenResult = aColorResult.green(),
+ aBlueResult = aColorResult.blue();
+
+ if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+ return;
+
+ // 3. abort the previous operation and start a new one
+ if(!isActiveOperationAborted())
+ return;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+
+ // 4. set the value to all results
+ static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL) {
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ if (aColorAttr.get() != NULL) {
+ aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+ ModelAPI_EventCreator::get()->sendUpdated(anObj, EVENT_DISP);
+ }
+ }
+ }
+ }
+ aMgr->finishOperation();
+ updateCommandStatus();
+}
+
//**************************************************************
void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
{