X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Tools.cpp;h=bd3c855cc0b8628317c957ba05a751613bc25d9b;hb=26a7489eb80cc314d2719eb88c243affff2d7428;hp=0114238db64c52e8c18e35f2d88954a3a2bb71e3;hpb=8ed331d9f0dc910fdcdfebd6d6e0ac108a79496c;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 0114238db..bd3c855cc 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_Tools.cpp -// Created: 11 July 2014 -// Author: Vitaly Smetannikov +// Copyright (C) 2014-2017 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" @@ -13,6 +27,7 @@ #include #include #include +#include #include #include @@ -32,9 +47,11 @@ #include #include #include +#include #include +#include #include #include @@ -118,7 +135,10 @@ void zeroMargins(QLayout* theLayout) 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()); @@ -127,8 +147,10 @@ void activateWindow(QWidget* theWidget, const QString& theInfo) void setFocus(QWidget* theWidget, const QString& theInfo) { + activateWindow(theWidget); theWidget->setFocus(); - + // rectangle of focus is not visible on tool button widgets + theWidget->repaint(); #ifdef DEBUG_SET_FOCUS qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str()); #endif @@ -266,6 +288,15 @@ QAction* createAction(const QIcon& theIcon, const QString& theText, return anAction; } +#ifdef _DEBUG +QString objectName(const ObjectPtr& theObj) +{ + if (!theObj.get()) + return ""; + + return theObj->data()->name().c_str(); +} + QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo) { QString aFeatureStr = "feature"; @@ -309,6 +340,7 @@ QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo) return aFeatureStr; } +#endif typedef QMap ShapeTypes; static ShapeTypes myShapeTypes; @@ -343,23 +375,34 @@ int shapeType(const QString& theType) } 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(aObj); ResultPtr aResult = std::dynamic_pointer_cast(aObj); + FolderPtr aFolder = std::dynamic_pointer_cast(aObj); ResultParameterPtr aConstruction = std::dynamic_pointer_cast(aResult); hasResult |= (aResult.get() != NULL); hasFeature |= (aFeature.get() != NULL); + hasFolder |= (aFolder.get() != NULL); hasParameter |= (aConstruction.get() != NULL); if (hasFeature) hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL); - if (hasFeature && hasResult && hasParameter && hasCompositeOwner) + + if (!hasResultInHistory && aResult.get()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aResult); + hasResultInHistory = aFeature.get() && aFeature->isInHistory(); + } + + if (hasFeature && hasResult && hasParameter && hasCompositeOwner && hasFeature) break; } } @@ -410,20 +453,17 @@ void setDefaultDeviationCoefficient(const 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 aColor = Config_PropManager::color(theSection, theName, theDefault); + std::vector aColor = Config_PropManager::color(theSection, theName); return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB); } @@ -478,6 +518,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(); @@ -695,7 +747,12 @@ void flushUpdated(ObjectPtr theObject) { 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_OBJECT_UPDATED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); blockUpdateViewer(false); } @@ -1001,10 +1058,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; @@ -1065,6 +1138,9 @@ 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 if(aDrawer->HasOwnPointAspect()) { Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect(); if(aPixMap->IsEmpty()) { @@ -1082,6 +1158,7 @@ void setPointBallHighlighting(AIS_Shape* theAIS) aDrawer->SetPointAspect(aPntAspect); theAIS->SetHilightAttributes(aDrawer); } +#endif } } // namespace ModuleBase_Tools