X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Tools.cpp;h=a60e3c2bb875230bac764226e769b7b16d20b6d0;hb=d3b52be3c4baef3776ee87bf5c194d33b0d4aa4d;hp=42a5381b549bb6b93674df708554c4a90d43c2e0;hpb=8578511c4164ad4fd45ad1c6a92cc8aaacba5972;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 42a5381b5..a60e3c2bb 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -37,11 +39,12 @@ #include #include #include +#include +#include #include #include #include -#include #include #include #include @@ -50,7 +53,11 @@ #include +#include #include +#include +#include +#include #include #include @@ -175,28 +182,32 @@ QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon) { 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) @@ -516,6 +527,18 @@ TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape) return aShapeType; } +TopoDS_Shape getSelectedShape(const std::shared_ptr& thePrs) +{ + if (thePrs->shape().get()) + return thePrs->shape()->impl(); + + 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(); @@ -660,18 +683,16 @@ bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, } else if (aType == ModelAPI_AttributeSelection::typeId()) { AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast(theAttribute); - ResultPtr aResult = std::dynamic_pointer_cast(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(theAttribute); - ResultPtr aResult = std::dynamic_pointer_cast(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 = @@ -1005,7 +1026,8 @@ bool askToDelete(const std::set theFeatures, .arg(anOtherFeatureNames.join(aSep)); } if (!aParamFeatureNames.empty()) { - const char* aMsg = "Parameters are used in the following features: %1.\nThese features will " + const char* aMsg = "Parameters are used directly and through a sequence " + "of dependencies in the following features: %1.\nThese features will " "be deleted.\nOr parameters could be replaced by their values.\n"; aText += QString(QObject::tr(aMsg)) .arg(aParamFeatureNames.join(aSep)); @@ -1044,10 +1066,26 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set& t if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) { aFeature = ModelAPI_Feature::feature(anObject); } - theFeatures.insert(aFeature); + if (aFeature.get()) + theFeatures.insert(aFeature); } } +//************************************************************** +void convertToFolders(const QObjectPtrList& theObjects, + std::set& theFolders) +{ + QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); + for(; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + FolderPtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature.get()) + theFolders.insert(aFeature); + } +} + + +//************************************************************** QString translate(const Events_InfoMessage& theMessage) { QString aMessage; @@ -1107,10 +1145,15 @@ void setPointBallHighlighting(AIS_Shape* theAIS) } Handle(Graphic3d_AspectMarker3d) anAspect; - Handle(Prs3d_Drawer) aDrawer = theAIS->HilightAttributes(); -#ifdef USE_OCCT_720 - // to do: implement ball highlighting, in 7.2.0 this drawer is NULL -#else + 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()) { @@ -1126,9 +1169,131 @@ void setPointBallHighlighting(AIS_Shape* theAIS) aPntAspect->SetAspect(anAspect); } aDrawer->SetPointAspect(aPntAspect); - theAIS->SetHilightAttributes(aDrawer); + theAIS->SetDynamicHilightAttributes(aDrawer); } -#endif +} + +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 aDoc = aMgr->activeDocument(); + + aParameter = aDoc->addFeature("Parameter"); + 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 aDoc = aMgr->activeDocument(); + FeaturePtr aParamFeature; + int aNbFeatures = aDoc->numInternalFeatures(); + std::string aName = theName.toStdString(); + 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 aDoc = aMgr->activeDocument(); + FeaturePtr aParamFeature; + int aNbFeatures = aDoc->numInternalFeatures(); + std::string aName = theName.toStdString(); + 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::string generateName(const AttributePtr& theAttribute, + ModuleBase_IWorkshop* theWorkshop) +{ + std::string aName; + if (theAttribute.get() != NULL) { + ModuleBase_Operation* anOperation = theWorkshop->currentOperation(); + + 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::stringstream aStreamName; + aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str(); + aName = aStreamName.str(); + } + } + return aName; } } // namespace ModuleBase_Tools