theB = (int)(aColor.Blue()*255.);
}
+bool GeomAPI_AISObject::setDeflection(const double theDeflection)
+{
+ bool isModified = false;
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (!anAIS.IsNull()) {
+ Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+ if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) {
+ aDrawer->SetDeviationCoefficient(theDeflection);
+ isModified = true;
+ }
+ }
+
+ return isModified;
+}
+
+double GeomAPI_AISObject::getDeflection() const
+{
+ double aDeflection = -1;
+
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (!anAIS.IsNull()) {
+ Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+ aDeflection = aDrawer->DeviationCoefficient();
+ }
+ return aDeflection;
+}
+
+
bool GeomAPI_AISObject::empty() const
{
Handle(AIS_InteractiveObject) anAIS = const_cast<GeomAPI_AISObject*>(this)
GEOMAPI_EXPORT
void getColor(int& theR, int& theG, int& theB);
+ /** \brief Assigns the deflection to the shape
+ * \param[in] theDeflection value of deflection
+ */
+ GEOMAPI_EXPORT
+ bool setDeflection(const double theDeflection);
+
+ /** \brief Returns deflection for the shape
+ * \return double value
+ */
+ GEOMAPI_EXPORT
+ double getDeflection() const;
+
/// \return Current width of the lines of shape
GEOMAPI_EXPORT
double width();
#include <Model_ResultBody.h>
#include <Model_BodyBuilder.h>
-#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Tools.h>
#include <Config_PropManager.h>
#include <ModelAPI_Events.h>
myConnect = ConnectionNotComputed;
}
-void Model_ResultBody::initAttributes()
-{
- // append the color attribute. It is empty, the attribute will be filled by a request
- DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault)
{
bool myWasConcealed;
public:
- /// Request for initialization of data model of the result: adding all attributes
- virtual void initAttributes();
-
/// Returns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault);
#include <Model_Objects.h>
#include <Model_BodyBuilder.h>
#include <Model_Document.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
#include <Events_Loop.h>
updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
}
-void Model_ResultCompSolid::initAttributes()
-{
- DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
{
ModelAPI_ResultCompSolid::store(theShape);
/// Removes the stored builders
MODEL_EXPORT virtual ~Model_ResultCompSolid();
- /// Request for initialization of data model of the object: adding all attributes
- MODEL_EXPORT virtual void initAttributes();
-
/// Stores the shape (called by the execution method). Creates sub-results for compsolid.
MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
#include <Model_ResultConstruction.h>
-#include <ModelAPI_AttributeIntArray.h>
#include <Config_PropManager.h>
#include <GeomAPI_PlanarEdges.h>
#include <GeomAlgoAPI_SketchBuilder.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
-void Model_ResultConstruction::initAttributes()
-{
- // append the color attribute. It is empty, the attribute will be filled by a request
- DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault)
{
bool myIsInHistory;
bool myIsInfinite;
public:
- /// Request for initialization of data model of the result: adding all attributes
- virtual void initAttributes();
-
/// Retuns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault);
#include <Model_ResultGroup.h>
#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeIntArray.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
myOwnerData = theOwnerData;
}
-void Model_ResultGroup::initAttributes()
-{
- // append the color attribute. It is empty, the attribute will be filled by a request
- DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault)
{
{
std::shared_ptr<ModelAPI_Data> myOwnerData; ///< data of owner of this result
public:
- /// Request for initialization of data model of the result: adding all attributes
- virtual void initAttributes();
/// Retuns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeDouble.h>
#include <Model_Document.h>
#include <Model_Application.h>
#include <Events_Loop.h>
data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId()));
data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId());
+ data()->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
if (aDocRef->isInitialized() && // initialized immideately means already exist and will be loaded
!Model_Application::getApplication()->hasDocument(aDocRef->docId()))
#include <ModelAPI_Events.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
+
#include <Events_Loop.h>
ModelAPI_Result::~ModelAPI_Result()
{
}
+void ModelAPI_Result::initAttributes()
+{
+ // append the color attribute. It is empty, the attribute will be filled by a request
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
+ aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
{
if (myIsDisabled != theFlag) {
return MY_COLOR_ID;
}
+ /// Reference to the deflection of the result.
+ /// The double value is used. The values is in [0, 1] range
+ inline static const std::string& DEFLECTION_ID()
+ {
+ static const std::string MY_DEFLECTION_ID("Deflection");
+ return MY_DEFLECTION_ID;
+ }
+
/// Returns true if the result is concealed from the data tree (referenced by other objects)
MODELAPI_EXPORT virtual bool isConcealed();
MODELAPI_EXPORT virtual bool isDisabled();
/// Request for initialization of data model of the result: adding all attributes
- virtual void initAttributes() {};
+ MODELAPI_EXPORT virtual void initAttributes();
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Result();
XGUI_ContextMenuMgr.h
XGUI_CustomPrs.h
XGUI_DataModel.h
+ XGUI_DeflectionDialog.h
XGUI_Displayer.h
XGUI_ErrorDialog.h
XGUI_ErrorMgr.h
XGUI_ContextMenuMgr.cpp
XGUI_CustomPrs.cpp
XGUI_DataModel.cpp
+ XGUI_DeflectionDialog.cpp
XGUI_Displayer.cpp
XGUI_ErrorDialog.cpp
XGUI_ErrorMgr.cpp
aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
addAction("COLOR_CMD", aAction);
+ aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
+ addAction("DEFLECTION_CMD", aAction);
+
aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
addAction("SHOW_CMD", aAction);
if (myWorkshop->canChangeColor())
action("COLOR_CMD")->setEnabled(true);
+ if (myWorkshop->canChangeDeflection())
+ action("DEFLECTION_CMD")->setEnabled(true);
+
ModuleBase_IModule* aModule = myWorkshop->module();
if (aModule)
aModule->updateObjectBrowserMenu(myActions);
if (myWorkshop->canChangeColor())
action("COLOR_CMD")->setEnabled(true);
+ if (myWorkshop->canChangeDeflection())
+ action("DEFLECTION_CMD")->setEnabled(true);
+
action("DELETE_CMD")->setEnabled(true);
}
aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
aList.append(action("SHOW_FEATURE_CMD"));
myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
aList.append(action("SHOW_FEATURE_CMD"));
myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
// Group menu
aList.append(action("SHOW_ONLY_CMD"));
aList.append(mySeparator);
aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
// Result part menu
myViewerMenu[ModelAPI_ResultPart::group()] = aList;
aList.append(action("SHOW_ONLY_CMD"));
aList.append(mySeparator);
aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
myViewerMenu[ModelAPI_ResultBody::group()] = aList;
// Group menu
myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
aActions.append(mySeparator);
//aActions.append(action("MOVE_CMD"));
aActions.append(action("COLOR_CMD"));
+ aActions.append(action("DEFLECTION_CMD"));
+
aActions.append(action("CLEAN_HISTORY_CMD"));
aActions.append(action("DELETE_CMD"));
}
// hide all is shown always even if selection in the viewer is empty
aActions.append(action("HIDEALL_CMD"));
aActions.append(action("COLOR_CMD"));
+ aActions.append(action("DEFLECTION_CMD"));
theMenu->addActions(aActions);
#include <ModuleBase_IModule.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Session.h>
#include <Config_PropManager.h>
#include <vector>
#include <QColor>
+double getDeflection(const ResultPtr& theResult)
+{
+ double aDeflection = -1;
+ // get color from the attribute of the result
+ if (theResult.get() != NULL &&
+ theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) {
+ AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
+ if (aDoubleAttr.get() && aDoubleAttr->isInitialized())
+ aDeflection = aDoubleAttr->value();
+ }
+ return aDeflection;
+}
-void getColor(ResultPtr theResult, std::vector<int>& theColor)
+void getColor(const ResultPtr& theResult, std::vector<int>& theColor)
{
theColor.clear();
// get color from the attribute of the result
}
}
+double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject)
+{
+ return Config_PropManager::real("Visualization", "result_deflection", "0.001");
+}
+
XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
: myWorkshop(theWorkshop)
{
}
-void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
+void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector<int>& theColor)
{
getColor(theResult, theColor);
if (theColor.empty())
getDefaultColor(theResult, false, theColor);
}
+double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult)
+{
+ double aDeflection = getDeflection(theResult);
+ if (aDeflection < 0)
+ aDeflection = getDefaultDeflection(theResult);
+ return aDeflection;
+}
+
bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
{
aColor[2] = aNewColor.blue();
}
aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+ aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized;
}
ModuleBase_IModule* aModule = myWorkshop->module();
aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized;
/// Returns color of a result object
/// \param theResult a result object
/// \param theColor a color in form of RGB vector
- static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
+ static void getResultColor(const ResultPtr& theResult, std::vector<int>& theColor);
+
+ /// Returns deflection of a result object
+ /// \param theResult a result object
+ /// \return theDeflection a real value
+ static double getResultDeflection(const ResultPtr& theResult);
/// Returns the default object color. It obtains colorConfigInfo of the object
/// and find it in preferences. If there are no this color in preference and an empty
static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
std::vector<int>& theColor);
+ /// Returns the default deflection value. The value is obtained from the application preferences
+ /// \param theObject an investigated object
+ /// \return deflection value
+ static double XGUI_EXPORT getDefaultDeflection(const ObjectPtr& theObject);
protected:
XGUI_Workshop* myWorkshop; ///< the current workshop
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: XGUI_DeflectionDialog.cpp
+// Created: 27 Jul 2016
+// Author: Natalia ERMOLAEVA
+
+#include <XGUI_DeflectionDialog.h>
+
+#include <ModelAPI_Tools.h>
+
+#include <QDoubleSpinBox>
+
+#include <QLabel>
+#include <QButtonGroup>
+#include <QGridLayout>
+#include <QRadioButton>
+#include <QDialogButtonBox>
+
+XGUI_DeflectionDialog::XGUI_DeflectionDialog(QWidget* theParent)
+ : QDialog(theParent)
+{
+ setWindowTitle("Deflection");
+ QGridLayout* aLay = new QGridLayout(this);
+
+ myDeflection = new QDoubleSpinBox(this);
+ myDeflection->setRange(0, 1);
+ aLay->addWidget(new QLabel("Deviation", this), 0, 0);
+ aLay->addWidget(myDeflection, 0, 1);
+
+ QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, this);
+ connect(aButtons, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(aButtons, SIGNAL(rejected()), this, SLOT(reject()));
+ aLay->addWidget(aButtons, 1, 0, 1, 2);
+}
+
+void XGUI_DeflectionDialog::setDeflection(const double& theValue)
+{
+ myDeflection->setValue(theValue);
+}
+
+double XGUI_DeflectionDialog::getDeflection() const
+{
+ return myDeflection->value();
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: XGUI_DeflectionDialog.hxx
+// Created: 27 Jul 2016
+// Author: Natalia ERMOLAEVA
+
+#ifndef XGUI_DeflectionDialog_H
+#define XGUI_DeflectionDialog_H
+
+#include "XGUI.h"
+
+#include <QDialog>
+
+class QButtonGroup;
+class QDoubleSpinBox;
+
+/**
+* \ingroup GUI
+* A class of dialog to chose a deflection value. The deflection value is in range [0, 1]
+*/
+class XGUI_DeflectionDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ /// Constructor
+ /// \param theParent a parent widget for the dialog
+ XGUI_EXPORT XGUI_DeflectionDialog(QWidget* theParent);
+
+ XGUI_EXPORT virtual ~XGUI_DeflectionDialog() {};
+
+ /// Initializes the dialog with the given value.
+ /// \param theValue the deflection value
+ void setDeflection(const double& theDeflection);
+
+ /// Returns the current deflection value.
+ /// \return a double value
+ double getDeflection() const;
+
+private:
+ QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice
+ QDoubleSpinBox* myDeflection; /// a deflection value
+};
+
+#endif
#include "XGUI_ActionsMgr.h"
#include "XGUI_MenuMgr.h"
#include "XGUI_ColorDialog.h"
+#include "XGUI_DeflectionDialog.h"
#include "XGUI_ContextMenuMgr.h"
#include "XGUI_Displayer.h"
#include "XGUI_ErrorDialog.h"
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Feature.h>
Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
-
+
+ Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection",
+ Config_Prop::Double, "0.001");
+
if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
myViewerSelMode.append(TopAbs_FACE);
if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
updateCommandStatus();
}
+//**************************************************************
+bool XGUI_Workshop::canChangeDeflection() 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());
+ aTypes.insert(ModelAPI_ResultPart::group());
+
+ return hasResults(aObjects, aTypes);
+}
+
+void setDeflection(ResultPtr theResult, const double theDeflection)
+{
+ if (!theResult.get())
+ return;
+
+ AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
+ if (aDeflectionAttr.get() != NULL)
+ aDeflectionAttr->setValue(theDeflection);
+}
+
+
+//**************************************************************
+void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
+{
+ AttributeDoublePtr aDoubleAttr;
+ // 1. find the current color of the object. This is a color of AIS presentation
+ // The objects are iterated until a first valid color is found
+ double aDeflection = -1;
+ foreach(ObjectPtr anObject, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get()) {
+ aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
+ }
+ else {
+ // TODO: remove the obtaining a color from the AIS object
+ // this does not happen never because:
+ // 1. The color can be changed only on results
+ // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
+ AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+ if (anAISObj.get()) {
+ aDeflection = anAISObj->getDeflection();
+ }
+ }
+ if (aDeflection > 0)
+ break;
+ }
+ if (aDeflection < 0)
+ return;
+
+ if (!abortAllOperations())
+ return;
+ // 2. show the dialog to change the value
+ XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
+ aDlg->setDeflection(aDeflection);
+ aDlg->move(QCursor::pos());
+ bool isDone = aDlg->exec() == QDialog::Accepted;
+ if (!isDone)
+ return;
+
+ // 3. abort the previous operation and start a new one
+ SessionPtr aMgr = ModelAPI_Session::get();
+ QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+
+ // 4. set the value to all results
+ aDeflection = aDlg->getDeflection();
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+ if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
+ for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
+ setDeflection(aCompsolidResult->subResult(i), aDeflection);
+ }
+ }
+ setDeflection(aResult, aDeflection);
+ }
+ }
+ aMgr->finishOperation();
+ updateCommandStatus();
+}
+
//**************************************************************
#define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
for (int i = 0; i < aDoc->size(aGroupName); i++) { \
//! \return boolean value
bool canChangeColor() const;
- //! Change color of the features if it is possible
+ //! Change color of the results if it is possible
//! The operation is available for construction, body and group results
//! theObjects a list of selected objects
void changeColor(const QObjectPtrList& theObjects);
+ //! Returns true if there is at least one selected body/construction/group result
+ //! \return boolean value
+ bool canChangeDeflection() const;
+
+ //! Change deflection of the results if it is possible
+ //! The operation is available for construction, body and group results
+ //! theObjects a list of selected objects
+ void changeDeflection(const QObjectPtrList& theObjects);
+
//! Show the given features in 3d Viewer
void showObjects(const QObjectPtrList& theList, bool isVisible);