+
+void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
+ const FeaturePtr& theSketch,
+ ModuleBase_IWorkshop* theWorkshop,
+ FeatureToSelectionMap& theSelection)
+{
+ if (theFeature.get() == NULL)
+ return;
+
+ std::set<AttributePtr> aSelectedAttributes;
+ std::set<ResultPtr> aSelectedResults;
+
+ ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+ Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ std::list<ResultPtr> aResults = theFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ {
+ ResultPtr aResult = *aIt;
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
+ if (aAISObj.get() == NULL)
+ continue;
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
+ {
+ Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
+ aContext->SelectedOwner());
+ if (aBRepOwner.IsNull())
+ continue;
+ Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
+ aBRepOwner->Selectable());
+ if (anIO != anAISIO)
+ continue;
+
+ if (aBRepOwner->HasShape()) {
+ const TopoDS_Shape& aShape = aBRepOwner->Shape();
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX) {
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
+ aShape, theSketch);
+ if (aPntAttr.get() != NULL)
+ aSelectedAttributes.insert(aPntAttr);
+ }
+ else if (aShapeType == TopAbs_EDGE &&
+ aSelectedResults.find(aResult) == aSelectedResults.end()) {
+ aSelectedResults.insert(aResult);
+ }
+ }
+ }
+ }
+ theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
+}
+
+void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
+ const FeaturePtr& theSketch,
+ ModuleBase_IWorkshop* theWorkshop,
+ const FeatureToSelectionMap& theSelection,
+ SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
+{
+ if (theFeature.get() == NULL)
+ return;
+
+ FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
+ std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
+ std::set<ResultPtr> aSelectedResults = anIt.value().second;
+
+ ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+ Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ // 1. found the feature's owners. Check the AIS objects of the constructions
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
+ if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
+ SelectMgr_IndexedMapOfOwner aSelectedOwners;
+ aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+ for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
+ Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
+ if (!anOwner.IsNull())
+ anOwnersToSelect.Add(anOwner);
+ }
+ }
+
+ // 2. found the feature results's owners
+ std::list<ResultPtr> aResults = theFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ {
+ ResultPtr aResult = *aIt;
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
+ if (aAISObj.get() == NULL)
+ continue;
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
+ SelectMgr_IndexedMapOfOwner aSelectedOwners;
+ aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+ for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
+ Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
+ if ( anOwner.IsNull() || !anOwner->HasShape() )
+ continue;
+ const TopoDS_Shape& aShape = anOwner->Shape();
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX) {
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
+ if (aPntAttr.get() != NULL &&
+ aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
+ anOwnersToSelect.Add(anOwner);
+ }
+ }
+ else if (aShapeType == TopAbs_EDGE) {
+ bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
+ if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
+ anOwnersToSelect.FindIndex(anOwner) <= 0)
+ anOwnersToSelect.Add(anOwner);
+ }
+ }
+ }
+}
+
+void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
+{
+ ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
+ if (aPropertyPanel) {
+ const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
+ foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
+ if (isToConnect) {
+ connect(aWidget, SIGNAL(beforeValuesChanged()),
+ this, SLOT(onBeforeValuesChangedInPropertyPanel()));
+ connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
+ connect(aWidget, SIGNAL(afterValuesChanged()),
+ this, SLOT(onAfterValuesChangedInPropertyPanel()));
+ }
+ else {
+ disconnect(aWidget, SIGNAL(beforeValuesChanged()),
+ this, SLOT(onBeforeValuesChangedInPropertyPanel()));
+ disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
+ disconnect(aWidget, SIGNAL(afterValuesChanged()),
+ this, SLOT(onAfterValuesChangedInPropertyPanel()));
+ }
+ }
+ }
+}
+
+ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
+{
+ return myModule->workshop()->currentOperation();
+}
+
+void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
+ const bool isToDisplay)
+{
+ if (!theOperation || theOperation->isEditOperation())
+ return;
+
+ ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ // 1. change visibility of the object itself, here the presentable object is processed,
+ // e.g. constraints features
+ FeaturePtr aFeature = theOperation->feature();
+ std::list<ResultPtr> aResults = aFeature->results();
+ if (isToDisplay)
+ aDisplayer->display(aFeature, false);
+ else
+ aDisplayer->erase(aFeature, false);
+
+ // change visibility of the object results, e.g. non-constraint features
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+ if (isToDisplay) {
+ aDisplayer->display(*aIt, false);
+ }
+ else {
+ aDisplayer->erase(*aIt, false);
+ }
+ }
+ aDisplayer->updateViewer();
+}
+
+void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
+{
+ ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ ModuleBase_ISelection* aSelect = aWorkshop->selection();
+ QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
+
+ QMap<FeaturePtr, QList<AttributePtr> > aFeature2AttributeMap;
+ if (theHighlightedOnly) {
+ fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
+ }
+ else {
+ fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
+
+ QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+ fillFeature2Attribute(aSelected, aFeature2AttributeMap, myCurrentSketch);
+ }
+
+ // 1. it is necessary to save current selection in order to restore it after the features moving
+ myCurrentSelection.clear();
+ QMap<FeaturePtr, QList<AttributePtr> >::const_iterator anIt = aFeature2AttributeMap.begin(),
+ aLast = aFeature2AttributeMap.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = anIt.key();
+ getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
+ }
+ //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+}
+
+void PartSet_SketcherMgr::restoreSelection()
+{
+ //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+ ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+ FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
+ aSLast = myCurrentSelection.end();
+ SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+ for (; aSIt != aSLast; aSIt++) {
+ anOwnersToSelect.Clear();
+ getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
+ anOwnersToSelect);
+ aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+ }
+}