X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Tools.h;h=69567cc0fa8b9b013eb751f81b0970977fee2dc8;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=6101364200a1494b6aba5e21ad80a8fd5ff90ff1;hpb=3b676e8f67d0b110ecee42985223b99fc181532b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h old mode 100755 new mode 100644 index 610136420..69567cc0f --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_Tools.h -// Created: 11 July 2014 -// Author: Vitaly Smetannikov +// Copyright (C) 2014-2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #ifndef ModuleBase_Tools_H #define ModuleBase_Tools_H @@ -12,83 +25,95 @@ #include #include +#include #include #include #include +#include #include +#include #include +#include + +#include class QWidget; class QLayout; class QDoubleSpinBox; +class QAction; +class ModuleBase_IWorkshop; class ModuleBase_ParamIntSpinBox; class ModuleBase_ParamSpinBox; -class ModuleBase_IWorkshop; +class ModuleBase_ViewerPrs; class GeomAPI_Shape; +class Events_InfoMessage; + namespace ModuleBase_Tools { -/* - * Methods to adjust margins and spacings. - */ +/// Methods to adjust margins and spacings. MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget); MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout); MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget); MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout); -/* - * Calls the same-named Qt method for the given widget. - * It sets the top-level widget containing this widget to be the active window. - * An active window is a visible top-level window that has the keyboard input focus. - * \param theWidget a widget to be activated - * \param theIndo a debug information - */ +/// Calls the same-named Qt method for the given widget. +/// It sets the top-level widget containing this widget to be the active window. +/// An active window is a visible top-level window that has the keyboard input focus. +/// \param theWidget a widget to be activated +/// \param theIndo a debug information MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString()); -/* - * Calls the same-named Qt method for the given widget. - * Gives the keyboard input focus to this widget (or its focus proxy) if this widget or - * one of its parents is the active window. - * \param theWidget a widget to be activated - * \param theIndo a debug information - */ +/// Calls the same-named Qt method for the given widget. +/// Gives the keyboard input focus to this widget (or its focus proxy) if this widget or +/// one of its parents is the active window. +/// \param theWidget a widget to be activated +/// \param theIndo a debug information MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString()); -//! Sets or removes the shadow effect to the widget -//! \param theWidget a widget to be styled -//! \param isSetEffect if true, the shadow effect is set, overwise cleared -//! \return resulting pixmap +/// Sets or removes the shadow effect to the widget +/// \param theWidget a widget to be styled +/// \param isSetEffect if true, the shadow effect is set, otherwise cleared +/// \return resulting pixmap MODULEBASE_EXPORT void setShadowEffect(QWidget* theWidget, const bool isSetEffect); -/** - * \ingroup GUI - * Methods to modify a resource pixmap - */ +/// \ingroup GUI +/// Methods to modify a resource pixmap -//! Create composite pixmap. -//! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates -//! specified relatively to the upper left corner of \a theIcon. +/// Create composite pixmap. +/// Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates +/// specified relatively to the upper left corner of \a theIcon. -//! \param theAdditionalIcon resource text of the additional pixmap -//! \param theIcon resource text of the background pixmap -//! \return resulting pixmap +/// \param theAdditionalIcon resource text of the additional pixmap +/// \param theIcon resource text of the background pixmap +/// \return resulting pixmap MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon); -//! Generates the pixmap lighter than the resources pixmap. -//! Pixmap \a theIcon is lighted according to the given value. -//! If the lighter value is greater than 100, this functions returns a lighter pixmap. -//! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100, -//! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified. - -//! \param resource text of the pixmap -//! \param theLighterValue a lighter factor -//! \return resulting pixmap +/// Create composite pixmap. +/// Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates +/// specified relatively to the upper left corner of \a theIcon. + +/// \param theAdditionalIcon additional pixmap +/// \param theIcon background pixmap +/// \return resulting pixmap +MODULEBASE_EXPORT QPixmap composite(const QImage& theAdditionalIcon, QImage& theIcon); + +/// Generates the pixmap lighter than the resources pixmap. +/// Pixmap \a theIcon is lighted according to the given value. +/// If the lighter value is greater than 100, this functions returns a lighter pixmap. +/// Setting lighter value to 150 returns a color that is 50% brighter. +/// If the factor is less than 100, +/// the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified. + +/// \param resource text of the pixmap +/// \param theLighterValue a lighter factor +/// \return resulting pixmap MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200); /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged) @@ -116,51 +141,77 @@ MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int the /// \param theText a new value MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText); +/// Creates an action filled with the parameters +/// \param theIcon an action icon +/// \param theText an icon text +/// \param theParent an action object +/// \param theReceiver an object to process action triggered signal +/// \param theMember a slot to process the action triggered signal +/// \param theToolTip an action tool tip information, if empty the text is used +/// \param theStatusTip an action status tip information, if empty the text is used +MODULEBASE_EXPORT QAction* createAction(const QIcon& theIcon, const QString& theText, + QObject* theParent, const QObject* theReceiver = 0, + const char* theMember = "", + const QString& theToolTip = QString(), + const QString& theStatusTip = QString()); + +#ifdef _DEBUG +/// Returns name of data of the object if it is not NULL +/// \param theObj an object +/// \return a string +MODULEBASE_EXPORT QString objectName(const ObjectPtr& theObj); + /// Converts the object to the feature or a result and generate information string /// \param theObj an object /// \param isUseAttributesInfo a flag whether the attribute values information is used /// \return a string -MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false); +MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, + const bool isUseAttributesInfo = false); +#endif /// Converts string value (name of shape type) to shape enum value /// \param theType - string with shape type name /// \return TopAbs_ShapeEnum value -MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType); +MODULEBASE_EXPORT int shapeType(const QString& theType); /// Checks whether the object is a sub result. It gets the feature of the object, /// obtains all results of the feature and check if the object is a sub result /// \return boolean result MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject); -/*! -Check types of objects which are in the given list -\param theObjects the list of objects -\param hasResult will be set to true if list contains Result objects -\param hasFeature will be set to true if list contains Feature objects -\param hasParameter will be set to true if list contains Parameter objects -\param hasCompositeOwner will be set to true if list contains Sub-Feature objects -*/ +/// Check types of objects which are in the given list +/// \param theObjects the list of objects +/// \param hasResult will be set to true if list contains Result objects +/// \param hasFeature will be set to true if list contains Feature objects +/// \param hasParameter will be set to true if list contains Parameter objects +/// \param hasCompositeOwner will be set to true if list contains Sub-Feature objects +/// \param hasResultInHistory will be set to true if one of result is in history +/// \param hasFolder will be set to true if one of folder is in the list MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, - bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner); - -/*! Sets the default coeffient into the driver calculated accordingly the shape type. -It provides 1.e-4 for a shape withe Edge shape type -\param theShape a shape to define the deviation coeffient, -\param theDrawer a drawer -*/ + bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner, + bool& hasResultInHistory, bool& hasFolder, bool &hasGroupsOnly); + +/// Sets the default coeffient into the driver calculated accordingly the shape type. +/// It provides 1.e-4 for results of construction type +/// \param theResult a result object to define the deviation coefficient +/// \param theDrawer a drawer +//MODULEBASE_EXPORT void setDefaultDeviationCoefficient( +// const std::shared_ptr& theResult, +// const Handle(Prs3d_Drawer)& theDrawer); + +/// Sets the default coeffient into the driver calculated accordingly the shape type. +/// It provides 1.e-4 for a shape withe Edge shape type +/// \param theShape a shape to define the deviation coefficient, +/// \param theDrawer a drawer MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer); -/*! Obtains the color from the property manager and converts it to the OCCT color -\param theSection a property section -\param theName a property item name -\param theDefault a default color value -\return quantity color -*/ +/// Obtains the color from the property manager and converts it to the OCCT color +/// \param theSection a property section +/// \param theName a property item name +/// \return quantity color MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection, - const std::string& theName, - const std::string& theDefault); - + const std::string& theName); /// Returns the object from the attribute /// \param theObj an object @@ -170,6 +221,12 @@ MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute); /// \param theObj an object MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape); +/// Returns either presentation shape or shape of BREP owner if it is casted to it +/// \param thePrs selection presentation +/// \return shape +MODULEBASE_EXPORT TopoDS_Shape getSelectedShape( + const std::shared_ptr& thePrs); + /// Returns list of parameters accessible in the active part and partset /// \theParameters a list of parameter names MODULEBASE_EXPORT void getParameters(QStringList& theParameters); @@ -187,10 +244,26 @@ MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorksh /// \param theWorkshop to find an attribute for the given shape for attribute reference /// \param theTemporarily if it is true, do not store and name the added in the data framework /// It is useful for attribute selection -MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, +MODULEBASE_EXPORT bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, + const std::shared_ptr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const bool theTemporarily); + +/// Set the object to the attribute depending on the attribute type. If it is a list, +/// the values are appended if they are not in the list yet. +/// \param theAttribute an attribute where the object and shape are set +/// \param theObject an object +/// \param theShape a shape +/// \param theWorkshop to find an attribute for the given shape for attribute reference +/// \param theTemporarily if it is true, do not store and name the added in the data framework +/// \param theCheckIfAttributeHasObject if it is true, the check isInList is called +/// It is useful for attribute selection +/// \return true if the attribute is filled with the given parameters +MODULEBASE_EXPORT bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, const std::shared_ptr& theShape, ModuleBase_IWorkshop* theWorkshop, - const bool theTemporarily = false); + const bool theTemporarily, + const bool theCheckIfAttributeHasObject); /// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found /// using current module of the given workshop. @@ -207,6 +280,142 @@ MODULEBASE_EXPORT void flushUpdated(ObjectPtr theObject); /// \param theValue a boolean value MODULEBASE_EXPORT void blockUpdateViewer(const bool theValue); +/// Generates a wrapped string to be less than value with '\n' separators +/// \param theValue a boolean value +/// \param theWidget a widget to know the font +/// \param theMaxLineInPixels a maximum line width in pixels +MODULEBASE_EXPORT QString wrapTextByWords(const QString& theValue, QWidget* theWidget, + int theMaxLineInPixels = 150); + +/// Generates a locale to disable thousands separator for spin box +/// (to avoid inconsistency of double-2-string and string-2-double conversion) +/// \return locale +MODULEBASE_EXPORT QLocale doubleLocale(); + +/// Returns a container of referenced feature to the current object in the object document. +/// \param theObject an object, which will be casted to a feature type +/// \param theRefFeatures an output container +void MODULEBASE_EXPORT refsToFeatureInFeatureDocument(const ObjectPtr& theObject, + std::set& theRefFeatures); + + +/// Returns true if the object if a sub child of the feature. The feature is casted to the +/// composite one. If it is possible, the sub object check happens. The method is applied +/// recursively to the feature subs. +/// \param theObject a candidate to be a sub object +/// \param theFeature a candidate to be a composite feature +/// \return a boolean value +//bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature); + + +/// Returns true if the result is a sub object of some composite object +/// \param theObject a result object +/// \returns boolean value +//bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject); + + +/// Returns first result of the feature: the object itself if it is a result of +/// first result of the object's feature +/// \param theObject an object +/// \return first result or NULL +std::shared_ptr MODULEBASE_EXPORT firstResult(const ObjectPtr& theObject); + +/// Returns true if the list contains at least one feature from the module document(PartSet) +/// The Part features are skipped. +/// \param theFeatures a list of features +/// \bool true if it is found +bool MODULEBASE_EXPORT hasModuleDocumentFeature(const std::set& theFeatures); + +/// Shows a dialog box about references. Ask whether they should be also removed. +/// \param theFeatures a list of features +/// \param theReferences a map of all references to the features +/// \param theParent a parent widget for the question message box +/// \param theReferencesToDelete an out set for references features to be removed +/// \return true if in message box answer is Yes +bool MODULEBASE_EXPORT askToDelete(const std::set aFeatures, + const std::map >& theReferences, + QWidget* theParent, + std::set& theReferencesToDelete, + const std::string& thePrefixInfo = ""); + +/// Shows a message box about conflicting constraints. +/// \param theParent a parent widget for the message box +/// \param theWarningText text describing the cause of the conflict +bool MODULEBASE_EXPORT warningAboutConflict(QWidget* theParent, const std::string& theWarningText); + +/// Converts a list of objects to set of corresponded features. If object is result, it is ignored +/// because the feature only might be removed. But if result is in a parameter group, the feature +/// of this parameter is to be removed +/// \param theObjects a list of objects +/// \param theFeatures an out container of features +void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, + std::set& theFeatures); + + +/// Converts a list of objects to set of folders. +/// \param theObjects a list of objects +/// \param theFeatures an out container of features +void MODULEBASE_EXPORT convertToFolders(const QObjectPtrList& theObjects, + std::set& theFolders); + + +/// Returns translation from the given data. +/// If translation is not exists then it returns a string +/// from the info data without translation +/// \param theMessage a message which have to be translated +QString MODULEBASE_EXPORT translate(const Events_InfoMessage& theMessage); + +/// Returns translation from the given data. +/// If translation is not exists then it returns a string +/// from the info data without translation +/// \param theContext context of the message (Feature Id) +/// \param theMessage a message which have to be translated +QString MODULEBASE_EXPORT translate(const std::string& theContext, const std::string& theMessage); + +/// Set Highlighting of points as a Ball shape +/// \param theAIS - the presentation +void MODULEBASE_EXPORT setPointBallHighlighting(AIS_InteractiveObject* theAIS); + +/// Creates a parameter from a given string +/// \theText a text wit equation +FeaturePtr MODULEBASE_EXPORT createParameter(const QString& theText); + +/// Edits parameter replacing its name and expression according to the given string +/// \theParam a editing parameter +/// \theText a text wit equation +void MODULEBASE_EXPORT editParameter(FeaturePtr theParam, const QString& theText); + +/// Returns True if a parameter with the given name already exists +/// \theName a name of parameter +bool MODULEBASE_EXPORT isNameExist(const QString& theName, FeaturePtr theIgnoreParameter); + +/// Find parameter by its name +/// \theName a name of parameter +FeaturePtr MODULEBASE_EXPORT findParameter(const QString& theName); + +/// Returns true if both shapes are the same. In case of compounds it +/// compares their contents. +/// \param theShape1 a first shape to compare +/// \param theShape2 a second shape to compare +/// \return true if both shapes are the same +bool MODULEBASE_EXPORT isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2); + +//----------- Class members ------------- +/// Returns a name in the next form: attribute_feature_name/attribute_id +/// \param theAttribute a model attribute +/// \param theWorkshop a workshop class instance +/// \return string value +std::wstring MODULEBASE_EXPORT generateName(const AttributePtr& theAttribute, + ModuleBase_IWorkshop* theWorkshop); + +/// Returns pixel ratio of a screen where main window is displayed +qreal MODULEBASE_EXPORT currentPixelRatio(); + +/// Set displaying status for elements from part depending on the settings +/// \param thePart a pointer of part +void MODULEBASE_EXPORT setDisplaying(std::shared_ptr thePart, + bool theDisplayFromScript = false); } #endif