-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_Tools.cpp
-// Created: 11 July 2014
-// Author: Vitaly Smetannikov
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// 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
+//
#include "ModuleBase_Tools.h"
#include <ModuleBase_ParamIntSpinBox.h>
#include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_Preferences.h>
#include <ModuleBase_WidgetFactory.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_IViewer.h>
#include <ModuleBase_IconFactory.h>
#include <ModuleBase_ResultPrs.h>
+#include <ModuleBase_ViewerPrs.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Expression.h>
+#include <ModelAPI_ResultField.h>
#include <Events_Loop.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Result.h>
-#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Folder.h>
#include <ModelGeomAlgo_Point2D.h>
+#ifdef HAVE_SALOME
+#include <SUIT_Application.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#endif
+
+#include <StdSelect_BRepOwner.hxx>
#include <TopoDS_Iterator.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PlaneAspect.hxx>
#include <GeomDataAPI_Point2D.h>
#include <Events_InfoMessage.h>
#include <QMessageBox>
#include <QAction>
#include <QTextCodec>
+#include <QWindow>
+#include <QScreen>
#include <sstream>
#include <string>
//#define DEBUG_ACTIVATE_WINDOW
//#define DEBUG_SET_FOCUS
-//#define DEBUG_SELECTION_INFO
-
-#ifdef DEBUG_SELECTION_INFO
-#include <ModuleBase_ISelection.h>
-#include <ModuleBase_ViewerPrs.h>
-
-#include <AIS_InteractiveContext.hxx>
-#include <AIS_ListOfInteractive.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <AIS_Shape.hxx>
-#include <TopoDS_Shape.hxx>
-#include <AIS_LocalContext.hxx>
-#include <NCollection_List.hxx>
-#include <StdSelect_BRepOwner.hxx>
-#include <TColStd_ListOfInteger.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#endif
#ifdef WIN32
# define FSEP "\\"
//******************************************************************
+ //! Waits for REDISPLAY message and set the Visible flag to the entities
+ //! according to Preferences choice.
+ class ModuleBase_RedisplayListener : public Events_Listener
+ {
+ public:
+ static std::shared_ptr<ModuleBase_RedisplayListener> instance()
+ {
+ static std::shared_ptr<ModuleBase_RedisplayListener>
+ anInstance(new ModuleBase_RedisplayListener);
+ return anInstance;
+ }
+
+ void processEvent(const std::shared_ptr<Events_Message>& theMessage)
+ {
+ if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY))
+ {
+#if HAVE_SALOME
+ // If the python script is being loaded now, the preferences should be used
+ // to display the required object
+ SUIT_Session* aSession = SUIT_Session::session();
+ if (!aSession)
+ return;
+ SUIT_Application * anApp = aSession->activeApplication();
+ if (!anApp)
+ return;
+ QVariant aVar = anApp->property("IsLoadedScript");
+ if (!aVar.isNull() && aVar.toBool()) {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
+ if (aSize > 0) {
+ ObjectPtr anPartObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anPartObject);
+ ModuleBase_Tools::setDisplaying(aPart, true);
+ }
+ }
+#endif
+ }
+ }
+
+ private:
+ ModuleBase_RedisplayListener()
+ {
+ Events_Loop::loop()->registerListener(this,
+ Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ };
+
+ static std::shared_ptr<ModuleBase_RedisplayListener>
+ RL = ModuleBase_RedisplayListener::instance();
+
//******************************************************************
void adjustMargins(QWidget* theWidget)
void activateWindow(QWidget* theWidget, const QString& theInfo)
{
- theWidget->activateWindow();
+ if (theWidget) {
+ theWidget->activateWindow();
+ theWidget->raise();
+ }
#ifdef DEBUG_ACTIVATE_WINDOW
qDebug(QString("activateWindow: %1").arg(theInfo).toStdString().c_str());
void setFocus(QWidget* theWidget, const QString& theInfo)
{
+ activateWindow(theWidget);
theWidget->setFocus();
-
+ // rectangle of focus is not visible on tool button widgets
+ theWidget->update();
#ifdef DEBUG_SET_FOCUS
qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
#endif
{
QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
QImage anAditional(theAdditionalIcon);
+ return composite(anAditional, anIcon);
+}
- if (anIcon.isNull())
+QPixmap composite(const QImage& theAdditionalIcon, QImage& theIcon)
+{
+ if (theIcon.isNull())
return QPixmap();
- int anAddWidth = anAditional.width();
- int anAddHeight = anAditional.height();
+ int anAddWidth = theAdditionalIcon.width();
+ int anAddHeight = theAdditionalIcon.height();
- int aWidth = anIcon.width();
- int aHeight = anIcon.height();
+ int aWidth = theIcon.width();
+ int aHeight = theIcon.height();
- int aStartWidthPos = aWidth - anAddWidth - 1;
- int aStartHeightPos = aHeight - anAddHeight - 1;
+ int aStartWidthPos = aWidth - anAddWidth;
+ int aStartHeightPos = aHeight - anAddHeight;
for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
{
for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
{
- if (qAlpha(anAditional.pixel(i, j)) > 0)
- anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
+ if (qAlpha(theAdditionalIcon.pixel(i, j)) > 0)
+ theIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, theAdditionalIcon.pixel(i, j));
}
}
- return QPixmap::fromImage(anIcon);
+ return QPixmap::fromImage(theIcon);
}
QPixmap lighter(const QString& theIcon, const int theLighterValue)
void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
{
- if (fabs(theSpin->value() - theValue) < tolerance)
+ if (!theSpin->text().isEmpty() && fabs(theSpin->value() - theValue) < tolerance)
return;
bool isBlocked = theSpin->blockSignals(true);
theSpin->setValue(theValue);
return anAction;
}
+#ifdef _DEBUG
+QString objectName(const ObjectPtr& theObj)
+{
+ if (!theObj.get())
+ return "";
+
+ return QString::fromStdWString(theObj->data()->name());
+}
+
QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
{
QString aFeatureStr = "feature";
if (aFeature.get()) {
aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
if (aFeature->data()->isValid()) {
- aFeatureStr.append(QString(", name=%1").arg(theObj->data()->name().c_str()).toStdString()
- .c_str());
+ aFeatureStr.append(QString(", name=%1")
+ .arg(QString::fromStdWString(theObj->data()->name())).toStdString().c_str());
}
if (isUseAttributesInfo) {
std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
return aFeatureStr;
}
-
-#ifdef DEBUG_SELECTION_INFO
-QString getShapeTypeInfo(const int theType)
-{
- QString anInfo = "Undefined";
- switch(theType) {
- case TopAbs_COMPOUND: anInfo = "compound"; break;
- case TopAbs_COMPSOLID: anInfo = "compsolid"; break;
- case TopAbs_SOLID: anInfo = "solid"; break;
- case TopAbs_SHELL: anInfo = "shell"; break;
- case TopAbs_FACE: anInfo = "face"; break;
- case TopAbs_WIRE: anInfo = "wire"; break;
- case TopAbs_EDGE: anInfo = "edge"; break;
- case TopAbs_VERTEX: anInfo = "vertex"; break;
- case TopAbs_SHAPE: anInfo = "shape"; break;
- case ModuleBase_ResultPrs::Sel_Result:
- anInfo = "result_shape"; break;
- default: break;
- }
- return anInfo;
-}
-
-QString getModeInfo(const int theMode)
-{
- QString anInfo = "Undefined";
- switch(theMode) {
- case 0: anInfo = "SHAPE(0)"; break;
- case 1: anInfo = "VERTEX(1)"; break;
- case 2: anInfo = "EDGE(2)"; break;
- case 3: anInfo = "WIRE(3)"; break;
- case 4: anInfo = "FACE(4)"; break;
- case 5: anInfo = "SHELL(5)"; break;
- case 6: anInfo = "SOLID(6)"; break;
- case 7: anInfo = "COMPSOLID(7)"; break;
- case 8: anInfo = "COMPOUND(8)"; break;
- case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
- case 101: anInfo = "Sel_Constraint(101)"; break;
- case 102: anInfo = "Sel_Dimension_All(102)"; break;
- case 103: anInfo = "Sel_Dimension_Line(103)"; break;
- case 104: anInfo = "Sel_Dimension_Text(104)"; break;
- default: break;
- }
- return anInfo;
-}
-
-QString displayedInteractiveObjects(Handle(AIS_InteractiveContext)& theContext,
- const bool theShapeInfoOnly = true)
-{
- if (theContext.IsNull())
- return "";
- AIS_ListOfInteractive aListOfIO;
- theContext->DisplayedObjects(aListOfIO, false);
- QStringList anObjects;
- AIS_ListIteratorOfListOfInteractive aIt;
- for (aIt.Initialize(aListOfIO); aIt.More(); aIt.Next()) {
- Handle(AIS_InteractiveObject) anAISIO = aIt.Value();
- Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISIO);
- if (theShapeInfoOnly && aShapePrs.IsNull())
- continue;
-
- QString anInfo = "IO";
- std::ostringstream aPtrStr;
- aPtrStr << "[" << anAISIO.Access() << "]";
- anInfo += aPtrStr.str().c_str();
-
- if (!aShapePrs.IsNull()) {
- const TopoDS_Shape& aShape = aShapePrs->Shape();
- if (aShape.IsNull()) {
- //Events_Error::throwException("An empty AIS presentation");
- }
- else
- anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
- }
- TColStd_ListOfInteger aTColModes;
- theContext->ActivatedModes(anAISIO, aTColModes);
- TColStd_ListIteratorOfListOfInteger itr( aTColModes );
- QIntList aModesActivatedForIO;
- bool isDeactivated = false;
- QStringList aModes;
- for (; itr.More(); itr.Next() ) {
- Standard_Integer aMode = itr.Value();
- aModes.append(getModeInfo(aMode));
- //int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
- }
- if (aModes.size() > 0)
- anInfo += QString(", activated modes: %1").arg(aModes.join(", "));
-
- anObjects += anInfo;
- }
- QString aValue = QString("displayedIO[%1]").arg(anObjects.size());
- if (anObjects.size() > 0)
- aValue += QString(":\n %1").arg(anObjects.join("\n "));
- return aValue;
-}
-
-QString activeOwners(Handle(AIS_InteractiveContext)& theContext, const bool theShapeInfoOnly = true)
-{
- if (theContext.IsNull())
- return "";
- Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
- TCollection_AsciiString aSelectionName = aLContext->SelectionName();
- aLContext->UnhilightPicked(Standard_False);
-
- NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
- aLContext->MainSelector()->ActiveOwners(anActiveOwners);
- NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
- Handle(SelectMgr_EntityOwner) anOwner;
- QStringList anObjects;
- for (; anOwnersIt.More(); anOwnersIt.Next()) {
- anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
- Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
- if (theShapeInfoOnly && BROwnr.IsNull())
- continue;
-
- QString anInfo = "Owner";
- std::ostringstream aPtrStr;
- aPtrStr << "[" << anOwner.Access() << "]";
- anInfo += aPtrStr.str().c_str();
-
- Handle(AIS_InteractiveObject) aAISObj =
- Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
- if (!aAISObj.IsNull()) {
- std::ostringstream aPtrStr;
- aPtrStr << "[" << aAISObj.Access() << "]";
- anInfo += QString(", selectable(IO): %1").arg(aPtrStr.str().c_str());
- }
-
- if (!BROwnr.IsNull() && BROwnr->HasShape()) {
- const TopoDS_Shape& aShape = BROwnr->Shape();
- if (aShape.IsNull()) {
- //Events_Error::throwException("An empty AIS presentation");
- }
- else
- anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
- }
- anObjects += anInfo;
- }
- QString aValue = QString("activeOwners[%1]").arg(anObjects.size());
- if (anObjects.size() > 0)
- aValue += QString(":\n %1").arg(anObjects.join("\n "));
- return aValue;
-}
-
-QString selectedOwners(Handle(AIS_InteractiveContext)& theContext,
- const bool theShapeInfoOnly = true)
-{
- QStringList anObjects;
- if (theContext.IsNull())
- return "";
-
- QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
- for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
- Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
- Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
- if (theShapeInfoOnly && BROwnr.IsNull())
- continue;
-
- if (aSelectedIds.contains((long)anOwner.Access()))
- continue;
- aSelectedIds.append((long)anOwner.Access());
-
- QString anInfo = "Owner";
- std::ostringstream aPtrStr;
- aPtrStr << "[" << anOwner.Access() << "]";
- anInfo += aPtrStr.str().c_str();
-
- if (!BROwnr.IsNull() && BROwnr->HasShape()) {
- const TopoDS_Shape& aShape = BROwnr->Shape();
- anInfo += QString(", shape type = %1").arg(getShapeTypeInfo(aShape.ShapeType()));
- }
- anObjects += anInfo;
- }
- QString aValue = QString("selectedOwners[%1]").arg(anObjects.size());
- if (anObjects.size() > 0)
- aValue += QString(":\n %1").arg(anObjects.join("\n "));
- return aValue;
-}
-#endif
-
-void selectionInfo(Handle(AIS_InteractiveContext)& theContext, const std::string& thePrefix)
-{
-#ifdef DEBUG_SELECTION_INFO
- QString aValue = QString("\n\n\nDEBUG_SELECTION_INFO for '%1'\n%2\n%3\n%4")
- .arg(thePrefix.c_str())
- .arg(displayedInteractiveObjects(theContext))
- .arg(activeOwners(theContext))
- .arg(selectedOwners(theContext));
- qDebug(aValue.toStdString().c_str());
#endif
-}
typedef QMap<QString, int> ShapeTypes;
static ShapeTypes myShapeTypes;
}
void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
- bool& hasParameter, bool& hasCompositeOwner)
+ bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory,
+ bool& hasFolder)
{
hasResult = false;
hasFeature = false;
hasParameter = false;
hasCompositeOwner = false;
+ hasResultInHistory = false;
+ hasFolder = false;
foreach(ObjectPtr aObj, theObjects) {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+ FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
- hasResult |= (aResult.get() != NULL);
+ hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
hasFeature |= (aFeature.get() != NULL);
+ hasFolder |= (aFolder.get() != NULL);
hasParameter |= (aConstruction.get() != NULL);
if (hasFeature)
hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
+ else if (aResult.get())
+ hasCompositeOwner |= (ModelAPI_Tools::bodyOwner(aResult) != NULL);
+
+ if (!hasResultInHistory && aResult.get()) {
+ aFeature = ModelAPI_Feature::feature(aResult);
+ hasResultInHistory = aFeature.get() && aFeature->isInHistory();
+ }
+
if (hasFeature && hasResult && hasParameter && hasCompositeOwner)
break;
}
{
if (theShape.IsNull())
return;
+ if (theDrawer.IsNull())
+ return;
std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
aGeomShape->setImpl(new TopoDS_Shape(theShape));
double aDeflection;
if (isConstruction)
- aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
- ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
+ aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
else
- aDeflection = Config_PropManager::real("Visualization", "body_deflection",
- ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+ aDeflection = Config_PropManager::real("Visualization", "body_deflection");
theDrawer->SetDeviationCoefficient(aDeflection);
}
Quantity_Color color(const std::string& theSection,
- const std::string& theName,
- const std::string& theDefault)
+ const std::string& theName)
{
- std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
+ std::vector<int> aColor = Config_PropManager::color(theSection, theName);
return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
}
return aShapeType;
}
+TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
+{
+ if (thePrs->shape().get())
+ return thePrs->shape()->impl<TopoDS_Shape>();
+
+ Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
+ if (!anOwner.IsNull())
+ return anOwner->Shape();
+
+ return TopoDS_Shape();
+}
+
void getParameters(QStringList& theParameters)
{
theParameters.clear();
int aSize = aDocument->size(aGroupId);
for (int i = 0; i < aSize; i++) {
ObjectPtr anObject = aDocument->object(aGroupId, i);
- std::string aParameterName = anObject->data()->name();
- theParameters.append(aParameterName.c_str());
+ std::wstring aParameterName = anObject->data()->name();
+ theParameters.append(QString::fromStdWString(aParameterName));
}
}
}
if (aType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
+ aHasObject = aSelectionListAttr->isInList(theObject, theShape, theTemporarily);
}
else if (aType == ModelAPI_AttributeRefList::typeId()) {
AttributeRefListPtr aRefListAttr =
} else if (aType == ModelAPI_AttributeSelection::typeId()) {
AttributeSelectionPtr aSelectAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aSelectAttr.get() != NULL) {
- aSelectAttr->setValue(aResult, theShape, theTemporarily);
+ aSelectAttr->setValue(theObject, theShape, theTemporarily);
}
}
if (aType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (!theCheckIfAttributeHasObject ||
- !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
- aSelectionListAttr->append(aResult, theShape, theTemporarily);
+ !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
+ aSelectionListAttr->append(theObject, theShape, theTemporarily);
}
else if (aType == ModelAPI_AttributeRefList::typeId()) {
AttributeRefListPtr aRefListAttr =
{
blockUpdateViewer(true);
+ // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
+ // (for the sketch result) to start processing of the sketch in the solver.
+ // TODO: these flushes should be moved in a separate method provided by Model
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES));
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_UPDATE_SELECTION));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
blockUpdateViewer(false);
}
int n = aWords.count();
QString aLine;
for (int i = 0; i < n; i++) {
- QString aLineExt = aLine + " " + aWords[i];
+ QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
qreal anWidthNonExt = tfm.boundingRect(aLine).width();
qreal anWidthExt = tfm.boundingRect(aLineExt).width();
qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
const std::string& thePrefixInfo)
{
QString aNotActivatedDocWrn;
- std::string aNotActivatedNames;
+ std::wstring aNotActivatedNames;
if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
aNotActivatedDocWrn =
- QObject::tr("Selected objects can be used in Part documents which are not loaded:%1.\n")
- .arg(aNotActivatedNames.c_str());
+ QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
+ .arg(QString::fromStdWString(aNotActivatedNames));
}
std::set<FeaturePtr> aFeaturesRefsTo;
continue;
if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
- aPartFeatureNames.append(aFeature->name().c_str());
+ aPartFeatureNames.append(QString::fromStdWString(aFeature->name()));
std::set<FeaturePtr> aRefFeatures;
std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
FeaturePtr aFeature = *anIt;
if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
aFeaturesRefsToParameterOnly.insert(aFeature);
- aParamFeatureNames.append(aFeature->name().c_str());
+ aParamFeatureNames.append(QString::fromStdWString(aFeature->name()));
}
}
aParamFeatureNames.sort();
aLast = theReferencesToDelete.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = *anIt;
+ if (aFeature->getKind() == "RemoveResults")
+ continue; // skip the remove results feature mentioning: result will be removed anyway
if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
- aPartFeatureNames.append(aFeature->name().c_str());
+ aPartFeatureNames.append(QString::fromStdWString(aFeature->name()));
else
- anOtherFeatureNames.append(aFeature->name().c_str());
+ anOtherFeatureNames.append(QString::fromStdWString(aFeature->name()));
}
aPartFeatureNames.sort();
anOtherFeatureNames.sort();
- bool aCanReplaceParameters = !aFeaturesRefsToParameterOnly.empty();
-
QMessageBox aMessageBox(theParent);
aMessageBox.setWindowTitle(QObject::tr("Delete features"));
aMessageBox.setIcon(QMessageBox::Warning);
aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
aMessageBox.setDefaultButton(QMessageBox::No);
- QString aText;
+ QString aText, aDetailedText;
if (!thePrefixInfo.empty())
aText = thePrefixInfo.c_str();
QString aSep = ", ";
if (!aNotActivatedDocWrn.isEmpty())
aText += aNotActivatedDocWrn;
if (!anOtherFeatureNames.empty()) {
- const char* aMsg = "Features are used in the following features: %1.\nThese "
- "features will be deleted.\n";
- aText += QString(QObject::tr(aMsg))
+ const char* aMsg = "The selected features are used in some\n"
+ "other features, which will also be deleted.\n";
+ const char* aMsgDetails = "The selected features are used"
+ " in the following features: %1.\n";
+ aText += QString(QObject::tr(aMsg));
+ aDetailedText += QString(QObject::tr(aMsgDetails))
.arg(anOtherFeatureNames.join(aSep));
}
if (!aParamFeatureNames.empty()) {
- const char* aMsg = "Parameters are used in the following features: %1.\nThese features will "
- "be deleted.\nOr parameters could be replaced by their values.\n";
- aText += QString(QObject::tr(aMsg))
+ const char* aMsg = "The selected parameters are used directly or through\n"
+ "a sequence of dependencies in some features.\n"
+ "These features will be deleted.\n"
+ "Or parameters could be replaced by their values.\n";
+ const char* aMsgDetails = "Parameters are used in the following features: %1.\n";
+ aText += QString(QObject::tr(aMsg));
+ aDetailedText += QString(QObject::tr(aMsgDetails))
.arg(aParamFeatureNames.join(aSep));
+#ifdef _DEBUG
QPushButton *aReplaceButton =
+#endif
aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
}
if (!aText.isEmpty()) {
- aText += "Would you like to continue?";
aMessageBox.setText(aText);
+ aMessageBox.setInformativeText(QObject::tr("Would you like to continue?"));
+ if (!aDetailedText.isEmpty())
+ aMessageBox.setDetailedText(aDetailedText);
aMessageBox.exec();
QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
aFeature = ModelAPI_Feature::feature(anObject);
}
- theFeatures.insert(aFeature);
+ if (aFeature.get())
+ theFeatures.insert(aFeature);
}
}
-void translate(const std::string& theContext, std::string& theMessage)
+//**************************************************************
+void convertToFolders(const QObjectPtrList& theObjects,
+ std::set<FolderPtr>& theFolders)
{
+ QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
+ for(; anIt != aLast; anIt++) {
+ ObjectPtr anObject = *anIt;
+ FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
+ if (aFeature.get())
+ theFolders.insert(aFeature);
+ }
+}
+
+
+//**************************************************************
+QString translate(const Events_InfoMessage& theMessage)
+{
+ QString aMessage;
+
+ if (!theMessage.empty()) {
+ std::string aStr = Config_Translator::translate(theMessage);
+ if (!aStr.empty()) {
+ std::string aCodec = Config_Translator::codec(theMessage);
+ aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ }
+ }
+
+ return aMessage;
+}
+
+QString translate(const std::string& theContext, const std::string& theMessage)
+{
+ QString aMessage;
+
if (!theMessage.empty()) {
std::string aStr = Config_Translator::translate(theContext, theMessage);
if (!aStr.empty()) {
std::string aCodec = Config_Translator::codec(theContext);
- theMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()).toStdString();
+ aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
}
}
+
+ return aMessage;
}
-void setPointBallHighlighting(AIS_Shape* theAIS)
+void setPointBallHighlighting(AIS_InteractiveObject* theAIS)
{
static Handle(Image_AlienPixMap) aPixMap;
if(aPixMap.IsNull()) {
aFile = std::string(anEnv) +
FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
} else {
- anEnv = getenv("OPENPARTS_ROOT_DIR");
+ anEnv = getenv("CADBUILDER_ROOT_DIR");
if (anEnv)
aFile = std::string(anEnv) + FSEP + "resources";
}
}
Handle(Graphic3d_AspectMarker3d) anAspect;
- Handle(Prs3d_Drawer) aDrawer = theAIS->HilightAttributes();
+ Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
+ if (aDrawer.IsNull()) {
+ if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
+ return;
+ aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
+ if (!aDrawer->HasOwnPointAspect()) {
+ aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
+ }
+ }
if(aDrawer->HasOwnPointAspect()) {
Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
if(aPixMap->IsEmpty()) {
aPntAspect->SetAspect(anAspect);
}
aDrawer->SetPointAspect(aPntAspect);
- theAIS->SetHilightAttributes(aDrawer);
+ theAIS->SetDynamicHilightAttributes(aDrawer);
}
}
+FeaturePtr createParameter(const QString& theText)
+{
+ FeaturePtr aParameter;
+ QStringList aList = theText.split("=");
+ if (aList.count() != 2) {
+ return aParameter;
+ }
+ QString aParamName = aList.at(0).trimmed();
+
+ if (isNameExist(aParamName, FeaturePtr())) {
+ return aParameter;
+ }
+
+ if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
+ return aParameter;
+ }
+
+ QString aExpression = aList.at(1).trimmed();
+ if (aExpression.isEmpty()) {
+ return aParameter;
+ }
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+
+ aParameter = aDoc->addFeature("Parameter", false);
+ if (aParameter.get()) {
+ AttributeStringPtr aNameAttr = aParameter->string("variable");
+ aNameAttr->setValue(aParamName.toStdString());
+
+ AttributeStringPtr aExprAttr = aParameter->string("expression");
+ aExprAttr->setValue(aExpression.toStdString());
+ aParameter->execute();
+
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ return aParameter;
+}
+
+void editParameter(FeaturePtr theParam, const QString& theText)
+{
+ QStringList aList = theText.split("=");
+ QString aParamName = aList.at(0).trimmed();
+
+ QString aExpression = aList.at(1).trimmed();
+ if (aExpression.isEmpty()) {
+ return;
+ }
+
+ if (isNameExist(aParamName, theParam)) {
+ return;
+ }
+ AttributeStringPtr aNameAttr = theParam->string("variable");
+ aNameAttr->setValue(aParamName.toStdString());
+
+ AttributeStringPtr aExprAttr = theParam->string("expression");
+ aExprAttr->setValue(aExpression.toStdString());
+ theParam->execute();
+
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+}
+
+bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+ FeaturePtr aParamFeature;
+ int aNbFeatures = aDoc->numInternalFeatures();
+ std::wstring aName = theName.toStdWString();
+ for (int i = 0; i < aNbFeatures; i++) {
+ aParamFeature = aDoc->internalFeature(i);
+ if (aParamFeature && aParamFeature->getKind() == "Parameter") {
+ if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
+ return true;
+ }
+ }
+ return false;
+}
+
+FeaturePtr findParameter(const QString& theName)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+ FeaturePtr aParamFeature;
+ int aNbFeatures = aDoc->numInternalFeatures();
+ std::wstring aName = theName.toStdWString();
+ for (int i = 0; i < aNbFeatures; i++) {
+ aParamFeature = aDoc->internalFeature(i);
+ if (aParamFeature && aParamFeature->getKind() == "Parameter") {
+ if (aParamFeature->name() == aName)
+ return aParamFeature;
+ }
+ }
+ return FeaturePtr();
+}
+
+
+//********************************************************************
+std::wstring generateName(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop)
+{
+ std::wstring aName;
+ if (theAttribute.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature.get()) {
+ std::string aXmlCfg, aDescription;
+ theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
+
+ ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
+ std::string anAttributeTitle;
+ aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
+
+ std::wstringstream aStreamName;
+ aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
+ aName = aStreamName.str();
+ }
+ }
+ return aName;
+}
+
+bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
+{
+ // In case of compound we cannot rely on simple comparison method.
+ // If the compound is generated by Group feature then this compound is alwais new.
+ // So, we have to compare content of these compounds
+ if (theShape1.ShapeType() != theShape2.ShapeType())
+ return false;
+
+ if (theShape1.ShapeType() != TopAbs_COMPOUND)
+ return theShape1.IsSame(theShape2);
+
+ TopoDS_Iterator aIt1(theShape1);
+ TopoDS_Iterator aIt2(theShape2);
+
+ for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
+ if (!(aIt1.Value()).IsSame(aIt2.Value()))
+ return false;
+ }
+ return true;
+}
+
+qreal currentPixelRatio()
+{
+ QWindowList aWnds = qApp->topLevelWindows();
+ if (aWnds.size() > 0)
+ return aWnds.first()->devicePixelRatio();
+ return qApp->primaryScreen()->devicePixelRatio();
+}
+
+
+// Set displaying status to every element on group
+static void setDisplayingByLoop(DocumentPtr theDoc, int theSize,
+ std::string theGroup, bool theDisplayFromScript, int theDisplayingId)
+{
+ for (int anIndex = theSize - 1; anIndex >= 0; --anIndex) {
+ ObjectPtr anObject = theDoc->object(theGroup, anIndex);
+ anObject->setDisplayed((theDisplayingId == 1 && anIndex == theSize - 1) || theDisplayingId == 2);
+ }
+}
+
+void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript)
+{
+ static bool isDoingDisplay = false;
+
+ if (isDoingDisplay)
+ return;
+
+ isDoingDisplay = true;
+ DocumentPtr aDoc = thePart->partDoc();
+ int aConstructionSize = aDoc->size(ModelAPI_ResultConstruction::group());
+ int aGroupSize = aDoc->size(ModelAPI_ResultGroup::group());
+ int aFieldSize = aDoc->size(ModelAPI_ResultField::group());
+ int aResultSize = aDoc->size(ModelAPI_ResultBody::group());
+
+ int aDisplayingId = -1;
+ if (theDisplayFromScript) {
+ aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General",
+ "part_visualization_script", -1);
+ // Increase ID to prevert using "As stored in HDF"
+ ++aDisplayingId;
+ }
+ else {
+ aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General",
+ "part_visualization_study", -1);
+
+ // if chosen "As stored in HDF" then don't change displaying
+ if (aDisplayingId == 0)
+ return;
+ }
+
+ setDisplayingByLoop(aDoc, aConstructionSize,
+ ModelAPI_ResultConstruction::group(), theDisplayFromScript, aDisplayingId);
+ setDisplayingByLoop(aDoc, aGroupSize, ModelAPI_ResultGroup::group(), theDisplayFromScript, aDisplayingId);
+ setDisplayingByLoop(aDoc, aFieldSize, ModelAPI_ResultField::group(), theDisplayFromScript, aDisplayingId);
+ setDisplayingByLoop(aDoc, aResultSize, ModelAPI_ResultBody::group(), theDisplayFromScript, aDisplayingId);
+ isDoingDisplay = false;
+}
+
} // namespace ModuleBase_Tools