#include <QMouseEvent>
#include <QApplication>
#include <QCursor>
+#include <QMessageBox>
//#define DEBUG_DO_NOT_BY_ENTER
: QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
myIsMouseOverWindow(false),
myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
- myIsPopupMenuActive(false), myIsConstraintsShown(true)
+ myIsPopupMenuActive(false)
{
ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
XGUI_Workshop* aWorkshop = aConnector->workshop();
connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
+
+ myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
+ myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
}
PartSet_SketcherMgr::~PartSet_SketcherMgr()
myIsDragging = true;
get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
- // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+
myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
launchEditing();
if (aFeature.get() != NULL) {
myIsDragging = true;
get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
- // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+
myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
// this is temporary commented in order to avoid the following wrong case:
}
}
}
- // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+
aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
- //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
myIsDragging = false;
}
// mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
// deselected). This flag should be restored in the slot, processed the mouse release signal.
- // TODO: Has to be commented out when SALOME patch on draw mode become avialable
- //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
- //aViewer->enableSelection(false);
-
ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
if (!aCurrentOperation)
return;
bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
{
- std::string aId = theOperation ? theOperation->id().toStdString() : "";
+ std::string anId = theOperation ? theOperation->id().toStdString() : "";
- return (aId == SketchPlugin_ConstraintLength::ID()) ||
- (aId == SketchPlugin_ConstraintDistance::ID()) ||
- (aId == SketchPlugin_ConstraintRadius::ID()) ||
- (aId == SketchPlugin_ConstraintAngle::ID());
+ return isDistanceKind(anId);
+}
+
+bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
+{
+ return (theKind == SketchPlugin_ConstraintLength::ID()) ||
+ (theKind == SketchPlugin_ConstraintDistance::ID()) ||
+ (theKind == SketchPlugin_ConstraintRadius::ID()) ||
+ (theKind == SketchPlugin_ConstraintAngle::ID());
}
void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
{
myIsMouseOverWindow = false;
- myIsConstraintsShown = true;
+ myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
+ myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
return aCanDisplay;
}
+void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
+{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation && myCurrentSketch.get()) {
+ // find results of the current operation
+ // these results should not be proposed to be deleted
+ FeaturePtr anOperationFeature = aFOperation->feature();
+ std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
+ std::set<ResultPtr> anOperationResults;
+ std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
+ aRLast = anOperationResultList.end();
+ for (; aRIt != aRLast; aRIt++)
+ anOperationResults.insert(*aRIt);
+
+ std::set<FeaturePtr> anObjectsToBeDeleted;
+ QStringList anObjectsToBeDeletedNames;
+ std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
+ for (; anIt != aLast; anIt++) {
+ ObjectPtr anObject = *anIt;
+ bool aCanErase = true;
+ // when the sketch operation is active, results of sketch sub-feature can not be hidden
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ // the result is found between current feature results
+ if (anOperationResults.find(aResult) != anOperationResults.end())
+ continue;
+
+ if (aResult.get()) {
+ // Display sketcher objects
+ for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
+ FeaturePtr aFeature = myCurrentSketch->subFeature(i);
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator anIt;
+ for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
+ aCanErase = *anIt != aResult;
+ }
+ }
+ }
+ if (!aCanErase) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
+ anObjectsToBeDeleted.insert(aFeature);
+ anObjectsToBeDeletedNames.append(aFeature->name().c_str());
+ }
+ }
+ }
+ if (!anObjectsToBeDeleted.empty()) {
+ QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
+ QString aMessage = tr("The following features have incorrect presentation and \
+will be hidden: %1. Would you like to delete them?")
+ .arg(aFeatureNames);
+ int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
+ aMessage, QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel);
+ if (anAnswer == QMessageBox::Ok) {
+ QObjectPtrList anObjects;
+ std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
+ aLast = anObjectsToBeDeleted.end();
+ for (; anIt != aLast; anIt++)
+ anObjects.append(*anIt);
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+ bool aIsOp = aMgr->isOperation();
+ if (!aIsOp)
+ aMgr->startOperation();
+ workshop()->deleteFeatures(anObjects);
+ //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+ //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ //Events_Loop::loop()->flush(aDeletedEvent);
+ //Events_Loop::loop()->flush(aRedispEvent);
+
+ if (!aIsOp)
+ aMgr->finishOperation();
+ }
+ }
+ }
+}
+
bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
{
bool aCanDisplay = myIsMouseOverWindow;
myModule->sketchReentranceMgr()->isInternalEditActive();
}
+const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
+{
+ return myIsConstraintsShown;
+}
+
bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
{
bool isFoundObject = false;
}
}
-void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
+void PartSet_SketcherMgr::onShowConstraintsToggle(bool theState, int theType)
{
- if (myIsConstraintsShown == theOn)
+ PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
+ if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
return;
if (myCurrentSketch.get() == NULL)
return;
- myIsConstraintsShown = theOn;
+ myIsConstraintsShown[aType] = theState;
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
const QStringList& aConstrIds = constraintsIdList();
for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
- if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
- if (myIsConstraintsShown)
- aSubFeature->setDisplayed(true);
+ std::string aKind = aSubFeature->getKind();
+ if (aConstrIds.contains(QString(aKind.c_str()))) {
+ bool isTypedConstraint = false;
+ if (aType == PartSet_Tools::Dimensional) {
+ isTypedConstraint = isDistanceKind(aKind);
+ }
else
- aSubFeature->setDisplayed(false);
+ isTypedConstraint = !isDistanceKind(aKind);
+
+ if (isTypedConstraint) {
+ if (theState)
+ aSubFeature->setDisplayed(true);
+ else
+ aSubFeature->setDisplayed(false);
+ }
}
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
}
-XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
+XGUI_Workshop* PartSet_SketcherMgr::workshop() const
{
ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ return aConnector->workshop();
+}
- return aWorkshop->operationMgr();
+XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
+{
+ return workshop()->operationMgr();
}