From: nds Date: Wed, 1 Apr 2015 15:48:59 +0000 (+0300) Subject: Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 X-Git-Tag: V_1.1.0~66 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=368eb86f8835d384a102ad84410a6c825c597a8c;hp=149dcd65a901bded64e17047cd5bf91921fa8bba;p=modules%2Fshaper.git Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 --- diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h index 5e6cc4bc8..b24e42278 100644 --- a/src/Config/Config_Prop.h +++ b/src/Config/Config_Prop.h @@ -4,8 +4,8 @@ // Created: 12 Aug 2014 // Author: Vitaly SMETANNIKOV -#ifndef Config_Prop_H -#define Config_Prop_H +#ifndef CONFIG_PROP_H +#define CONFIG_PROP_H #include "Config_def.h" @@ -26,7 +26,7 @@ class Config_Prop { Disabled, Space, - Bool, + Boolean, Color, String, Selector, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 3d8c5bbc8..3056c2682 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -72,8 +72,12 @@ void FeaturesPlugin_Extrusion::execute() for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - std::shared_ptr aFace = - aFacesNum == -1 ? aValueFace : aConstruction->face(aFaceIndex); + std::shared_ptr aFace; + if (aFacesNum == -1) { + aFace = aValueFace; + } else { + aFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + } GeomAlgoAPI_Extrusion aFeature(aFace, aSize); if(!aFeature.isDone()) { static const std::string aFeatureError = "Extrusion algorithm failed"; diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index c2da1a479..ee8cebc14 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -84,10 +84,15 @@ static TCollection_ExtendedString DocFileName(const char* theFileName, const std return aPath; } +bool Model_Document::isRoot() const +{ + return this == Model_Session::get()->moduleDocument().get(); +} + bool Model_Document::load(const char* theFileName) { Handle(Model_Application) anApp = Model_Application::getApplication(); - if (this == Model_Session::get()->moduleDocument().get()) { + if (isRoot()) { anApp->setLoadPath(theFileName); } TCollection_ExtendedString aPath(DocFileName(theFileName, myID)); @@ -161,7 +166,7 @@ bool Model_Document::load(const char* theFileName) std::dynamic_pointer_cast(Model_Session::get()); aSession->setActiveDocument(anApp->getDocument(myID), false); aSession->setCheckTransactions(false); - synchronizeFeatures(false, true); + synchronizeFeatures(false, true, true); aSession->setCheckTransactions(true); aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false); aSession->setActiveDocument(anApp->getDocument(myID), true); @@ -173,7 +178,7 @@ bool Model_Document::save(const char* theFileName, std::list& theRe { // create a directory in the root document if it is not yet exist Handle(Model_Application) anApp = Model_Application::getApplication(); - if (this == Model_Session::get()->moduleDocument().get()) { + if (isRoot()) { #ifdef WIN32 CreateDirectory(theFileName, NULL); #else @@ -241,9 +246,9 @@ bool Model_Document::save(const char* theFileName, std::list& theRe void Model_Document::close(const bool theForever) { std::shared_ptr aPM = Model_Session::get(); - if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) { + if (!isRoot() && this == aPM->activeDocument().get()) { aPM->setActiveDocument(aPM->moduleDocument()); - } else if (this == aPM->moduleDocument().get()) { + } else if (isRoot()) { // erase the active document if root is closed aPM->setActiveDocument(DocumentPtr()); } @@ -341,7 +346,7 @@ bool Model_Document::finishOperation() // this must be here just after everything is finished but before real transaction stop // to avoid messages about modifications outside of the transaction // and to rebuild everything after all updates and creates - if (Model_Session::get()->moduleDocument().get() == this) { // once for root document + if (isRoot()) { // once for root document Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); static std::shared_ptr aFinishMsg (new Events_Message(Events_Loop::eventByName("FinishOperation"))); @@ -371,7 +376,7 @@ bool Model_Document::finishOperation() if (!aResult && !myTransactions.empty() /* it can be for just created part document */) aResult = myTransactions.rbegin()->myOCAFNum != 0; - if (!aResult && Model_Session::get()->moduleDocument().get() == this) { + if (!aResult && isRoot()) { // nothing inside in all documents, so remove this transaction from the transactions list undoInternal(true, false); myDoc->ClearRedos(); @@ -398,7 +403,8 @@ void Model_Document::abortOperation() myDoc->Undo(); myDoc->ClearRedos(); } - synchronizeFeatures(true, false); // references were not changed since transaction start + // references were not changed since transaction start + synchronizeFeatures(true, false, isRoot()); // abort for all subs const std::set aSubs = subDocuments(true); std::set::iterator aSubIter = aSubs.begin(); @@ -446,8 +452,6 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron for(int a = 0; a < aNumTransactions; a++) myDoc->Undo(); - if (theSynchronize) - synchronizeFeatures(true, true); if (theWithSubs) { // undo for all subs const std::set aSubs = subDocuments(true); @@ -455,6 +459,9 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron for (; aSubIter != aSubs.end(); aSubIter++) subDoc(*aSubIter)->undoInternal(theWithSubs, theSynchronize); } + // after redo of all sub-documents to avoid updates on not-modified data (issue 370) + if (theSynchronize) + synchronizeFeatures(true, true, isRoot()); } void Model_Document::undo() @@ -485,12 +492,14 @@ void Model_Document::redo() for(int a = 0; a < aNumRedos; a++) myDoc->Redo(); - synchronizeFeatures(true, true); // redo for all subs const std::set aSubs = subDocuments(true); std::set::iterator aSubIter = aSubs.begin(); for (; aSubIter != aSubs.end(); aSubIter++) subDoc(*aSubIter)->redo(); + + // after redo of all sub-documents to avoid updates on not-modified data (issue 370) + synchronizeFeatures(true, true, isRoot()); } std::list Model_Document::undoList() const @@ -949,7 +958,8 @@ void Model_Document::initData(ObjectPtr theObj, TDF_Label theLab, const int theT theObj->initAttributes(); } -void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences) +void Model_Document::synchronizeFeatures( + const bool theMarkUpdated, const bool theUpdateReferences, const bool theFlush) { std::shared_ptr aThis = Model_Application::getApplication()->getDocument(myID); @@ -1040,11 +1050,13 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t myExecuteFeatures = false; aLoop->activateFlushes(true); - aLoop->flush(aCreateEvent); - aLoop->flush(aDeleteEvent); - aLoop->flush(anUpdateEvent); - aLoop->flush(aRedispEvent); - aLoop->flush(aToHideEvent); + if (theFlush) { + aLoop->flush(aCreateEvent); + aLoop->flush(aDeleteEvent); + aLoop->flush(anUpdateEvent); + aLoop->flush(aRedispEvent); + aLoop->flush(aToHideEvent); + } myExecuteFeatures = true; } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index ef7c98a10..59631304e 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -170,7 +170,9 @@ class Model_Document : public ModelAPI_Document //! Synchronizes myFeatures list with the updated document //! \param theMarkUpdated causes the "update" event for all features //! \param theUpdateReferences causes the update of back-references - void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences); + //! \param theFlush makes flush all events in the end of all modifications of this method + void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences, + const bool theFlush); //! Synchronizes the BackReferences list in Data of Features and Results void synchronizeBackRefs(); @@ -219,6 +221,9 @@ class Model_Document : public ModelAPI_Document /// Internally makes document know that feature was removed or added in history after creation MODEL_EXPORT virtual void addToHistory(const std::shared_ptr theObject); + /// Returns true if the document is root module document + bool isRoot() const; + friend class Model_Application; friend class Model_Session; friend class Model_Update; diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index e7f21bf88..8dcd0a11b 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -216,7 +216,7 @@ void Model_Session::setActiveDocument( if (aDoc.get()) { bool aWasChecked = myCheckTransactions; setCheckTransactions(false); - aDoc->synchronizeFeatures(false, true); + aDoc->synchronizeFeatures(false, true, true); if (aWasChecked) setCheckTransactions(true); } @@ -266,7 +266,7 @@ std::shared_ptr Model_Session::copy( aRT->SetRelocation(aSourceRoot, aTargetRoot); TDF_CopyTool::Copy(aDS, aRT); - aNew->synchronizeFeatures(false, true); + aNew->synchronizeFeatures(false, true, true); return aNew; } diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 2390df826..f1b4f50ff 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -50,7 +50,7 @@ Model_Update::Model_Update() aLoop->registerListener(this, kOpStartEvent); Config_PropManager::registerProp("Model update", "automatic_rebuild", "Rebuild immediately", - Config_Prop::Bool, "false"); + Config_Prop::Boolean, "false"); myIsAutomatic = Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true"; } diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index c7cd377cc..1d6837205 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -75,7 +76,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer - virtual void addViewerItems(QMenu* theMenu) const {} + /// \param theStdActions a map of standard actions + /// \return true if items are added and there is no necessity to provide standard menu + virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { return false; } /// Add menu atems for object browser into the given menu /// \param theMenu a popup menu to be shown in the object browser diff --git a/src/ModuleBase/ModuleBase_PagedContainer.cpp b/src/ModuleBase/ModuleBase_PagedContainer.cpp index 43fb4de22..b4e8b5690 100644 --- a/src/ModuleBase/ModuleBase_PagedContainer.cpp +++ b/src/ModuleBase/ModuleBase_PagedContainer.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 8b53074f9..9d74cc2fb 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -231,7 +231,7 @@ bool ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityO AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(aData->attribute(attributeID())); if (aShape->isEqual(aResult->shape())) - aSelectionListAttr->append(aResult, NULL); + aSelectionListAttr->append(aResult, GeomShapePtr()); else aSelectionListAttr->append(aResult, aShape); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 36bbd0314..34eb3e189 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -377,7 +377,7 @@ void ModuleBase_WidgetShapeSelector::storeAttributeValue() myObject = GeomValidators_Tools::getObject(anAttribute); myShape = getShape(); - myRefAttribute = NULL; + myRefAttribute = AttributePtr(); myIsObject = false; AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); if (aRefAttr) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 841387209..4c6856835 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -288,12 +288,12 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return aCanDisplay; } -void PartSet_Module::addViewerItems(QMenu* theMenu) const +bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - return; + return false; ModuleBase_ISelection* aSelection = myWorkshop->selection(); QObjectPtrList aObjects = aSelection->selectedPresentations(); @@ -307,10 +307,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const } } if (hasFeature) { - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD"); - theMenu->addAction(anAction); + theMenu->addAction(theStdActions["DELETE_CMD"]); } } bool isAuxiliary; @@ -319,6 +316,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const theMenu->addAction(anAction); anAction->setChecked(isAuxiliary); } + return true; } void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 891759c36..5264352dc 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -103,7 +103,9 @@ public: /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer - virtual void addViewerItems(QMenu* theMenu) const; + /// \param theStdActions a map of standard actions + /// \return true if items are added and there is no necessity to provide standard menu + virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; public slots: /// SLOT, that is called by no more widget signal emitted by property panel diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 8b1865829..82c0479bd 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -136,6 +136,6 @@ void PartSet_WidgetShapeSelector::removeExternal() anIgnoredFeatures.insert(sketch()); XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); } - myExternalObject = NULL; + myExternalObject = ObjectPtr(); } } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index fde907d81..5dc94ef4a 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -79,8 +79,7 @@ void SketchPlugin_ConstraintMirror::execute() ResultConstructionPtr aRC = std::dynamic_pointer_cast(*aMirrorIter); DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr(); - FeaturePtr aFeature = aDoc ? std::dynamic_pointer_cast( - aDoc->feature(aRC)) : FeaturePtr(); + FeaturePtr aFeature = aDoc ? aDoc->feature(aRC) : FeaturePtr(); if (aFeature) aDoc->removeFeature(aFeature); } diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index c7ee95fcc..e92cdb8c4 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -55,6 +55,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_ExternalValidator); aFactory->registerValidator("SketchPlugin_TangentAttr", new SketchPlugin_TangentAttrValidator); + aFactory->registerValidator("SketchPlugin_NotFixed", + new SketchPlugin_NotFixedValidator); + aFactory->registerValidator("SketchPlugin_EqualAttr", + new SketchPlugin_EqualAttrValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 358c82c1b..95da79b95 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -7,8 +7,10 @@ #include "SketchPlugin_Validators.h" #include "SketchPlugin_ConstraintDistance.h" #include "SketchPlugin_ConstraintCoincidence.h" +#include "SketchPlugin_ConstraintRigid.h" #include "SketchPlugin_Line.h" #include "SketchPlugin_Arc.h" +#include "SketchPlugin_Circle.h" #include "SketcherPrs_Tools.h" @@ -93,7 +95,8 @@ bool SketchPlugin_TangentAttrValidator::isValid( if (aOtherFea->getKind() != SketchPlugin_Arc::ID()) return false; } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) { - if (aOtherFea->getKind() != SketchPlugin_Line::ID()) + if (aOtherFea->getKind() != SketchPlugin_Line::ID() && + aOtherFea->getKind() != SketchPlugin_Arc::ID()) return false; } else return false; @@ -135,4 +138,76 @@ bool SketchPlugin_TangentAttrValidator::isValid( return false; } +bool SketchPlugin_NotFixedValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments) const +{ + std::shared_ptr aFeature = + std::dynamic_pointer_cast(theAttribute->owner()); + if (!aFeature) + return true; + + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + SketchPlugin_Sketch* aSketch = aFeature->sketch(); + int aNbFeatures = aSketch->numberOfSubs(); + for (int anInd = 0; anInd < aNbFeatures; anInd++) { + FeaturePtr aSubFeature = aSketch->subFeature(anInd); + if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature) + continue; + AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast( + aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A())); + if (aRefAttr->isObject()) { + if (aRefAttr->object() == aRAttr->object()) + return false; + } else if (aRefAttr->attr() == aRAttr->attr()) + return false; + } + return true; +} + +bool SketchPlugin_EqualAttrValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + std::string aParamA = theArguments.front(); + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr aRefAttr[2]; + aRefAttr[0] = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + aRefAttr[1] = aFeature->data()->refattr(aParamA); + + if (!aRefAttr[0]->isObject() || !aRefAttr[1]->isObject()) + return false; + + int aType[2] = {0, 0}; // types of attributes: 0 - incorrect, 1 - line, 2 - circle, 3 - arc + std::list anArguments; + for (int i = 0; i < 2; i++) { + ObjectPtr anObject = aRefAttr[i]->object(); + aFeature = ModelAPI_Feature::feature(anObject); + if (!aFeature) + return false; + + if (aFeature->getKind() == SketchPlugin_Line::ID()) { + aType[i] = 1; + continue; + } + if (aFeature->getKind() == SketchPlugin_Circle::ID()) { + aType[i] = 2; + continue; + } + if (aFeature->getKind() == SketchPlugin_Arc::ID()) { + aType[i] = 3; + continue; + } + // wrong type of attribute + return false; + } + + if ((aType[0] == 1 && aType[1] == 2) || + (aType[0] == 2 && aType[1] == 1)) + return false; + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 11721fbd1..47df37061 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -44,4 +44,37 @@ class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator }; +/**\class SketchPlugin_NotFixed + * \ingroup Validators + * \brief Validator for the rigid constraint input. + * + * It just checks there is no rigid constraint for the current feature. + */ +class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is not used in another rigid constraint + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + +/**\class SketchPlugin_EqualAttrValidator + * \ingroup Validators + * \brief Validator for the equal constraint input. + * + * It checks that attributes of the Equal constraint are correct. + */ +class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 7274cc18d..04730f8fc 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -151,6 +151,7 @@ + @@ -179,7 +180,7 @@ - + diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 9b0ae4325..f54067afa 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -687,10 +687,10 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint( for ( ; aBaseIter != aBaseList.end(); aBaseIter++, aMirIter++) { aRC = std::dynamic_pointer_cast(*aBaseIter); aBaseFeature = aRC ? aRC->document()->feature(aRC) : - std::dynamic_pointer_cast(*aBaseIter); + std::dynamic_pointer_cast(*aBaseIter); aRC = std::dynamic_pointer_cast(*aMirIter); aMirrorFeature = aRC ? aRC->document()->feature(aRC) : - std::dynamic_pointer_cast(*aMirIter); + std::dynamic_pointer_cast(*aMirIter); if (!aBaseFeature || !aMirrorFeature || aBaseFeature->getKind() != aMirrorFeature->getKind()) @@ -745,6 +745,7 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint( Slvs_hParam v = changeParameter(y, aParamIter); Slvs_Entity aPoint = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, u, v); myEntities.push_back(aPoint); + myEntOfConstr.push_back(true); aBothMiddlePoints[i] = aPoint.h; // additional constraint point-on-curve Slvs_Constraint aPonCircConstr = Slvs_MakeConstraint( @@ -752,6 +753,7 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint( aPoint.h, SLVS_E_UNKNOWN, aBothArcs[i], SLVS_E_UNKNOWN); myConstraints.push_back(aPonCircConstr); myConstraintMap[theConstraint].push_back(aPonCircConstr.h); + aNewConstraints.push_back(aPonCircConstr.h); } aBaseArcPoints[2] = aBothMiddlePoints[0]; @@ -806,16 +808,51 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint( for (aBaseIter = aBaseList.begin(); aBaseIter != aBaseList.end(); aBaseIter++) { aRC = std::dynamic_pointer_cast(*aBaseIter); aBaseFeature = aRC ? aRC->document()->feature(aRC) : - std::dynamic_pointer_cast(*aBaseIter); + std::dynamic_pointer_cast(*aBaseIter); if (!aBaseFeature) continue; std::list aPoints = aBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - std::list::iterator anIt = aPoints.begin(); - for ( ; anIt != aPoints.end(); anIt++) { + if (aBaseFeature->getKind() != SketchPlugin_Arc::ID()) { + std::list::iterator anIt = aPoints.begin(); + for ( ; anIt != aPoints.end(); anIt++) { + addTemporaryConstraintWhereDragged(*anIt); + } + } else { // Arcs are fixed by center and start points only (to avoid solving errors in SolveSpace) - if (aBaseFeature->getKind() == SketchPlugin_Arc::ID() && - (*anIt)->id() == SketchPlugin_Arc::END_ID()) - continue; - addTemporaryConstraintWhereDragged(*anIt); + AttributePtr aCenterAttr = aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()); + std::map::iterator aFound = myEntityAttrMap.find(aCenterAttr); + Slvs_hEntity anArcPoints[3] = {aFound->second, 0, 0}; + AttributePtr aStartAttr = aBaseFeature->attribute(SketchPlugin_Arc::START_ID()); + aFound = myEntityAttrMap.find(aStartAttr); + anArcPoints[1] = aFound->second; + AttributePtr aEndAttr = aBaseFeature->attribute(SketchPlugin_Arc::END_ID()); + aFound = myEntityAttrMap.find(aEndAttr); + anArcPoints[2] = aFound->second; + + bool isFixed[3] = {false, false, false}; + int aNbFixed = 0; // number of already fixed points on the arc + for (int i = 0; i < 3; i++) { + std::vector >::iterator aCoPtIter = myCoincidentPoints.begin(); + for (; aCoPtIter != myCoincidentPoints.end() && !isFixed[i]; aCoPtIter++) { + if (aCoPtIter->find(anArcPoints[i]) == aCoPtIter->end()) + continue; // the entity was not found in current set + + // Find one of already created SLVS_C_WHERE_DRAGGED constraints in current set of coincident points + std::vector::iterator aConstrIter = myConstraints.begin(); + for (; aConstrIter != myConstraints.end(); aConstrIter++) + if (aConstrIter->type == SLVS_C_WHERE_DRAGGED && + aCoPtIter->find(aConstrIter->ptA) != aCoPtIter->end()) { + isFixed[i] = true; + aNbFixed++; + break; // the SLVS_C_WHERE_DRAGGED constraint already exists + } + } + } + if (aNbFixed < 2) { // append constraints + if (!isFixed[0]) + addTemporaryConstraintWhereDragged(aCenterAttr); + if (!isFixed[1] && (isFixed[0] || aNbFixed == 0)) + addTemporaryConstraintWhereDragged(aStartAttr); + } } } } @@ -921,7 +958,7 @@ bool SketchSolver_ConstraintGroup::changeFilletConstraint( for (int indEnt = 0; aFilIter != aFilletList.end(); aFilIter++, indEnt++) { aRC = std::dynamic_pointer_cast(*aFilIter); aFilletFeature = aRC ? aRC->document()->feature(aRC) : - std::dynamic_pointer_cast(*aFilIter); + std::dynamic_pointer_cast(*aFilIter); if (!aFilletFeature) return false; aFilletEnt[indEnt] = changeEntityFeature(aFilletFeature); @@ -1080,7 +1117,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( std::map, Slvs_hEntity>::const_iterator aEntIter = myEntityAttrMap.find(theEntity); int aEntPos; - std::vector::const_iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise + std::vector::iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created aParamIter = myParams.end(); else { // the entity already exists @@ -1297,7 +1334,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal( // Try to find existent normal std::map, Slvs_hEntity>::const_iterator aEntIter = myEntityAttrMap.find(theNorm); - std::vector::const_iterator aParamIter; // looks to the first parameter of already existent entity or to the end of vector otherwise + std::vector::iterator aParamIter; // looks to the first parameter of already existent entity or to the end of vector otherwise if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created aParamIter = myParams.end(); else { // the entity already exists, update it @@ -1378,7 +1415,7 @@ bool SketchSolver_ConstraintGroup::updateWorkplane() // Purpose: create/update value of parameter // ============================================================================ Slvs_hParam SketchSolver_ConstraintGroup::changeParameter( - const double& theParam, std::vector::const_iterator& thePrmIter) + double theParam, std::vector::iterator& thePrmIter) { if (thePrmIter != myParams.end()) { // Parameter should be updated int aParamPos = thePrmIter - myParams.begin(); @@ -2143,9 +2180,16 @@ void SketchSolver_ConstraintGroup::makeMirrorEntity(const Slvs_hEntity& theBase, Slvs_Entity aBase = myEntities[Search(theBase, myEntities)]; Slvs_Entity aMirror = myEntities[Search(theMirror, myEntities)]; int i = 0; - while (aBase.point[i] != 0 && aMirror.point[i] != 0) { - makeMirrorEntity(aBase.point[i], aMirror.point[i], theMirrorLine); - i++; + if (aBase.type != SLVS_E_ARC_OF_CIRCLE) { + while (aBase.point[i] != 0 && aMirror.point[i] != 0) { + makeMirrorEntity(aBase.point[i], aMirror.point[i], theMirrorLine); + i++; + } + } else { + // swap mirroring first and last points of an arc + makeMirrorEntity(aBase.point[0], aMirror.point[0], theMirrorLine); + makeMirrorEntity(aBase.point[1], aMirror.point[2], theMirrorLine); + makeMirrorEntity(aBase.point[2], aMirror.point[1], theMirrorLine); } if (aBase.param[0] != 0 && aMirror.param[0] != 0) { // this is a point, copy it Slvs_Entity aMirrorLine = myEntities[Search(theMirrorLine, myEntities)]; @@ -2192,7 +2236,7 @@ Slvs_hConstraint SketchSolver_ConstraintGroup::changeMirrorPoints( std::map::iterator aMapIter = thePrevMirror.find(theBasePoint); if (aMapIter != thePrevMirror.end()) { thePrevMirror.erase(aMapIter); - std::vector::const_iterator anIter = thePrevConstr.begin(); + std::vector::iterator anIter = thePrevConstr.begin(); for (; anIter != thePrevConstr.end(); anIter++) if (anIter->ptA == theBasePoint) { if (anIter->ptB != theMirrorPoint) { diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index 73dc23d63..8ec26852f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -168,8 +168,8 @@ protected: * (the iterator will be increased if it does not reach the end of the list) * \return identifier of changed parameter; when the parameter cannot be created, returned ID is 0 */ - Slvs_hParam changeParameter(const double& theParam, - std::vector::const_iterator& thePrmIter); + Slvs_hParam changeParameter(double theParam, + std::vector::iterator& thePrmIter); /** \brief Removes specified entities and their parameters * \param[in] theEntities list of IDs of the entities to be removed diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 1fafcf506..bd346fb35 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -117,7 +117,7 @@ void SketchSolver_ConstraintManager::processEvent( for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { std::shared_ptr aFeature = std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature || aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) + if (!aFeature /*|| aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()*/) continue; changeConstraintOrEntity(aFeature); } diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 60c2e451a..86f1a1f3e 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject); @@ -34,6 +37,7 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConst const std::shared_ptr& thePlane) : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) { + } @@ -48,11 +52,15 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& return; std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); - - static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d (); - aPtA->SetType(Aspect_TOM_RING1); - aPtA->SetScale(2.); - aPtA->SetColor(myOwnColor); + myPoint = aPoint->impl(); + + static Handle(Graphic3d_AspectMarker3d) aPtA; + if (aPtA.IsNull()) { + aPtA = new Graphic3d_AspectMarker3d (); + aPtA->SetType(Aspect_TOM_RING1); + aPtA->SetScale(2.); + aPtA->SetColor(myOwnColor); + } Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(aPtA); Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1); @@ -64,6 +72,9 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { + Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10); + Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint); + aSelection->Add(aSp); } void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol) diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h index 9b9c4cd8a..72c7ec5d0 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.h +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -47,6 +47,7 @@ protected: private: SketchPlugin_Constraint* myConstraint; std::shared_ptr myPlane; + gp_Pnt myPoint; }; diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index 07957c4db..5e30f527f 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 282b1a31c..91d5c2f7c 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -227,40 +227,49 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const { - XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() > 0) { - //if (aObjects.size() == 1) - // theMenu->addAction(action("EDIT_CMD")); - bool isVisible = false; - bool isShading = false; - bool canBeShaded = false; - foreach(ObjectPtr aObject, aObjects) - { - ResultPtr aRes = std::dynamic_pointer_cast(aObject); - if (aRes && myWorkshop->displayer()->isVisible(aRes)) { - isVisible = true; - canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); - isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); - break; + bool aIsDone = false; + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aIsDone = aModule->addViewerItems(theMenu, myActions); + + if (!aIsDone) { + XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); + if (aObjects.size() > 0) { + //if (aObjects.size() == 1) + // theMenu->addAction(action("EDIT_CMD")); + bool isVisible = false; + bool isShading = false; + bool canBeShaded = false; + foreach(ObjectPtr aObject, aObjects) + { + ResultPtr aRes = std::dynamic_pointer_cast(aObject); + if (aRes && myWorkshop->displayer()->isVisible(aRes)) { + isVisible = true; + canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); + isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); + break; + } } + if (isVisible) { + if (canBeShaded) { + if (isShading) + theMenu->addAction(action("WIREFRAME_CMD")); + else + theMenu->addAction(action("SHADING_CMD")); + } + theMenu->addSeparator(); + theMenu->addAction(action("SHOW_ONLY_CMD")); + theMenu->addAction(action("HIDE_CMD")); + } else + theMenu->addAction(action("SHOW_CMD")); + //theMenu->addAction(action("DELETE_CMD")); } - if (isVisible) { - if (canBeShaded) { - if (isShading) - theMenu->addAction(action("WIREFRAME_CMD")); - else - theMenu->addAction(action("SHADING_CMD")); - } - theMenu->addSeparator(); - theMenu->addAction(action("SHOW_ONLY_CMD")); - theMenu->addAction(action("HIDE_CMD")); - } else - theMenu->addAction(action("SHOW_CMD")); - //theMenu->addAction(action("DELETE_CMD")); + if (myWorkshop->canChangeColor()) + theMenu->addAction(action("COLOR_CMD")); + if (myWorkshop->displayer()->objectsCount() > 0) + theMenu->addAction(action("HIDEALL_CMD")); } - if (myWorkshop->displayer()->objectsCount() > 0) - theMenu->addAction(action("HIDEALL_CMD")); if (!myWorkshop->isSalomeMode()) { theMenu->addSeparator(); QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); @@ -269,12 +278,7 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const aSubMenu->addActions(aMDI->actions()); } } - if (myWorkshop->canChangeColor()) - theMenu->addAction(action("COLOR_CMD")); - ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) - aModule->addViewerItems(theMenu); } void XGUI_ContextMenuMgr::connectObjectBrowser() const