X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_CustomPrs.cpp;h=aedc188b58d111159f80101a8a559d8b2c30fa82;hb=050220cc7654c7d7d175a07c72c74b70122f86c7;hp=3ae846074aac11e4ce844db2f5855c18c430fcba;hpb=1599bc97cf8f4eb2b4154586fe16c2f3b7a3895e;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 3ae846074..aedc188b5 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -5,6 +5,8 @@ // Author: Natalia ERMOLAEVA #include +#include +#include "PartSet_OperationPrs.h" #include #include @@ -21,136 +23,93 @@ #include #include +#include +#include #define OPERATION_PARAMETER_COLOR "255, 255, 0" PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop) { + myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); + myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop))); + + std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", + OPERATION_PARAMETER_COLOR); + myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + + myOperationPrs->setPointMarker(5, 2.); + myOperationPrs->setWidth(1); } -void PartSet_CustomPrs::setCustomized(const ObjectPtr& theObject) +bool PartSet_CustomPrs::isActive() const { -/* QMap > aNewCustomized; + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - QList aShapeList; - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get()) { - aNewCustomized[aResult] = aShapeList; - } - else { - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get()) { - std::list anAttributes = aFeature->data()->attributes(""); - std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); - for (; anIt != aLast; anIt++) { - AttributePtr anAttribute = *anIt; - ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute); - if (anObject.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aNewCustomized[aResult] = aShapeList; - } - else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) { - std::shared_ptr aCurSelList = - std::dynamic_pointer_cast(anAttribute); - for(int i = 0; i < aCurSelList->size(); i++) { - std::shared_ptr aSelAttribute = aCurSelList->value(i); - ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute); - if (anObject.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aNewCustomized[aResult] = aShapeList; - } - } - } - } - } + return aContext->IsDisplayed(anOperationPrs); +} + +void PartSet_CustomPrs::activate(const FeaturePtr& theFeature) +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + + if (anOperationPrs->canActivate(theFeature)) { + anOperationPrs->setFeature(theFeature); + if (theFeature.get()) + displayPresentation(); } +} + +void PartSet_CustomPrs::deactivate() +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + anOperationPrs->setFeature(FeaturePtr()); + + erasePresentation(); +} + + +void PartSet_CustomPrs::displayPresentation() +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - bool isDone = false; - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - // find objects which are not customized anymore - QMap > aNotCustomized; - QMap >::const_iterator anIt = myCustomized.begin(), - aLast = myCustomized.end(); - for (; anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - if (!aNewCustomized.contains(aResult)) - aNotCustomized[aResult] = aShapeList; + if (!aContext->IsDisplayed(anOperationPrs)) { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + aContext->Display(anOperationPrs); + aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); } + else + anOperationPrs->Redisplay(); +} - myCustomized.clear(); - // restore the previous state of the object if there is no such object in the new map - for (anIt = aNotCustomized.begin(), aLast = aNotCustomized.end(); anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult); - if (anAISObj.get()) { - Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl(); - aContext->Redisplay(anAISIO, false); - } - isDone = aDisplayer->customizeObject(aResult); - } +void PartSet_CustomPrs::erasePresentation() +{ + Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext->IsDisplayed(anOperationPrs)) + aContext->Remove(anOperationPrs); +} - // set customized for the new objects - myCustomized = aNewCustomized; - for (anIt = myCustomized.begin(), aLast = myCustomized.end(); anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult); - if (anAISObj.get()) - isDone = customisePresentation(aResult, anAISObj, 0) || isDone; - } - if (isDone) - aDisplayer->updateViewer();*/ +Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const +{ + Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl(); + return Handle(PartSet_OperationPrs)::DownCast(anAISIO); } -/*#include -#include -#include -#include -#include -#include */ -bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theCustomPrs) +void PartSet_CustomPrs::customize(const ObjectPtr& theObject) { - bool isDone = false; - if (myCustomized.contains(theResult)) { - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - isDone = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - /* - Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); - - const Handle(Prs3d_Presentation)& aPresentation = anAISIO->Presentation(); - if (!aPresentation.IsNull()) { - Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAISIO); - if (!aShapeAIS.IsNull()) { - TopExp_Explorer anExp(aShapeAIS->Shape(), TopAbs_VERTEX); - Handle(Prs3d_Drawer) aDrawer = aShapeAIS->Attributes(); - for (; anExp.More(); anExp.Next()) { - const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current(); - StdPrs_WFDeflectionShape::Add(aPresentation, aVertex, aDrawer); - } - } - } - thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*/ - } - /* - std::vector aColor; - - getResultColor(theResult, aColor); - - SessionPtr aMgr = ModelAPI_Session::get(); - if (aMgr->activeDocument() != theResult->document()) { - QColor aQColor(aColor[0], aColor[1], aColor[2]); - QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); - aColor[0] = aNewColor.red(); - aColor[1] = aNewColor.green(); - aColor[2] = aNewColor.blue(); + // the presentation should be recomputed if the previous AIS depend on the result + // [it should be hiddend] or the new AIS depend on it [it should be visualized] + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext->IsDisplayed(anOperationPrs)) { + // if there are performance poblems, to improve them, the necessity of redisplay can be checked + //bool aChanged = anOperationPrs->dependOn(theObject); + anOperationPrs->updateShapes(); + //aChanged = aChanged || anOperationPrs->dependOn(theObject); + //if (aChanged) + anOperationPrs->Redisplay(); } - return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/ - return isDone; }