aListeners.push_back(theListener);
}
+void Events_Loop::removeListener(Events_Listener* theListener)
+{
+ // remove the listener in myListeners map
+ std::map<char*, std::map<void*, std::list<Events_Listener*> > >::const_reverse_iterator
+ anIt = myListeners.rbegin();
+ while(anIt != myListeners.rend()) {
+ std::map<void*, std::list<Events_Listener*> > aLMap = anIt->second;
+ std::map<void*, std::list<Events_Listener*> >::const_reverse_iterator aLIt = aLMap.rbegin();
+ while (aLIt != aLMap.rend()) {
+ std::list<Events_Listener*> aListeners = aLIt->second;
+ std::list<Events_Listener*>::const_reverse_iterator aLsIt = aListeners.rbegin();
+ for (; aLsIt != aListeners.rend(); aLsIt++) {
+ if (*aLsIt == theListener) {
+ aListeners.remove(theListener);
+ aLMap[aLIt->first] = aListeners;
+ myListeners[anIt->first] = aLMap;
+ break;
+ }
+ }
+ if (aListeners.empty()) {
+ aLMap.erase(aLIt->first);
+ myListeners[anIt->first] = aLMap;
+ if (aLMap.empty())
+ break; // avoid incrementation of the iterator if the the container is empty
+ }
+ aLIt++;
+ }
+ if (anIt->second.empty()) {
+ myListeners.erase(anIt->first);
+ if (myListeners.empty())
+ break; // avoid incrementation of the iterator if the the container is empty
+ }
+ anIt++;
+ }
+
+ // remove the listener in myImmediateListeners map
+ std::map<char*, Events_Listener*>::const_reverse_iterator anImIt = myImmediateListeners.rbegin();
+ while(anImIt != myImmediateListeners.rend()) {
+ if (anImIt->second == theListener) {
+ myImmediateListeners.erase(anImIt->first);
+ if (myImmediateListeners.empty())
+ break; // avoid incrementation of the iterator if the the container is empty
+ }
+ anImIt++;
+ }
+}
+
void Events_Loop::flush(const Events_ID& theID)
{
if (!myFlushActive)
EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID,
void* theSender = 0, bool theImmediate = false);
+ //! Remove the listener from internal maps if it was registered there
+ //! \param theListener a listener
+ EVENTS_EXPORT void removeListener(Events_Listener* theListener);
+
//! Initializes sending of a group-message by the given ID
EVENTS_EXPORT void flush(const Events_ID& theID);
myHasConstraintShown[PartSet_Tools::Geometrical] = true;
myHasConstraintShown[PartSet_Tools::Dimensional] = true;
+ myHasConstraintShown[PartSet_Tools::Dimensional] = false;
Config_PropManager::registerProp("Visualization", "operation_parameter_color",
"Reference shape wireframe color in operation", Config_Prop::Color,
aLast = myHasConstraintShown.end();
for (; anIt != aLast; anIt++) {
myHasConstraintShown[anIt.key()];
- mySketchMgr->onShowConstraintsToggle(anIt.key(), anIt.value());
+ mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
}
}
ModuleBase_IModule::onFeatureTriggered();
}
+void PartSet_Module::editFeature(FeaturePtr theFeature)
+{
+ storeConstraintsState(theFeature->getKind());
+ ModuleBase_IModule::editFeature(theFeature);
+}
+
void PartSet_Module::launchOperation(const QString& theCmdId)
+{
+ storeConstraintsState(theCmdId.toStdString());
+ ModuleBase_IModule::launchOperation(theCmdId);
+}
+
+void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
{
if (myWorkshop->currentOperation() &&
myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
- const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
- mySketchMgr->showConstraintStates();
- myHasConstraintShown = aShownStates;
+ const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
+ mySketchMgr->showConstraintStates();
+ myHasConstraintShown = aShownStates;
}
- if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
+ if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str())) {
// Show constraints if a constraint was anOperation
- mySketchMgr->onShowConstraintsToggle(PartSet_Tools::Geometrical, true);
- mySketchMgr->onShowConstraintsToggle(PartSet_Tools::Dimensional, true);
+ mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
+ mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
+ mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
+ myHasConstraintShown[PartSet_Tools::Expressions]);
}
- ModuleBase_IModule::launchOperation(theCmdId);
}
-
void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
{
Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
ObjectPtr anObject = aDisplayer->getObject(thePrs);
if (anObject.get()) {
bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
- // customize sketcy symbol presentation
+ // customize sketch symbol presentation
if (thePrs.get()) {
Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
aCustomized = true;
}
}
+
+ // customize dimentional constrains
+ sketchMgr()->customizePresentation(anObject);
}
return aCustomized;
virtual bool createWidgets(ModuleBase_Operation* theOperation,
QList<ModuleBase_ModelWidget*>& theWidgets) const;
+ /// Launching of a edit operation on the feature
+ /// \param theFeature feature for editing
+ virtual void editFeature(FeaturePtr theFeature);
+
/// Creates an operation and send it to loop
/// \param theCmdId the operation name
virtual void launchOperation(const QString& theCmdId);
void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
protected:
+ /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
+ /// other dimensions are shown.
+ /// \param theFeatureKindId a feature kind
+ void storeConstraintsState(const std::string& theFeatureKindId);
+
/// Register validators for this module
virtual void registerValidators();
myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
+ myIsConstraintsShown[PartSet_Tools::Expressions] = false;
}
PartSet_SketcherMgr::~PartSet_SketcherMgr()
myIsMouseOverWindow = false;
myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
+ myIsConstraintsShown[PartSet_Tools::Expressions] = false;
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
}
}
+void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
+{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
+ PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)))
+ SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
+}
+
ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
{
return myModule->workshop()->currentOperation();
void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
{
PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
- if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
- return;
- if (myCurrentSketch.get() == NULL)
- return;
- myIsConstraintsShown[aType] = theState;
+ updateBySketchParameters(aType, theState);
+}
- ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+void PartSet_SketcherMgr::updateBySketchParameters(
+ const PartSet_Tools::ConstraintVisibleState& theType,
+ bool theState)
+{
+ if (myCurrentSketch.get() == NULL)
+ return;
- for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
- FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
- bool aProcessed = false;
- bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
- if (aProcessed)
- aSubFeature->setDisplayed(aConstraintDisplayed);
+ bool aPrevState = myIsConstraintsShown[theType];
+ myIsConstraintsShown[theType] = theState;
+
+ switch (theType) {
+ case PartSet_Tools::Geometrical:
+ case PartSet_Tools::Dimensional: {
+ if (aPrevState != theState) {
+ ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+ for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
+ FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
+ bool aProcessed = false;
+ bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
+ if (aProcessed)
+ aSubFeature->setDisplayed(aConstraintDisplayed);
+ }
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ }
+ break;
+ case PartSet_Tools::Expressions: {
+ /// call all sketch features redisplay, the expression state will be corrected in customize
+ /// of distance presentation
+ Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
+ }
+ break;
}
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
}
XGUI_Workshop* PartSet_SketcherMgr::workshop() const
/// \param thePreviousState the previous widget value state
void widgetStateChanged(int thePreviousState);
+ /// If the current operation is a dimention one, the style of dimension visualization is send for
+ /// the current object
+ /// \param theObject an object to be customized
+ void customizePresentation(const ObjectPtr& theObject);
+
+ /// Update sketch presentations according to the the state
+ /// \param theType a type of sketch visualization style
+ /// \param theState a boolean state
+ void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
+ bool theState);
+
public slots:
/// Process sketch plane selected event
void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
+private slots:
/// Toggle show constraints
void onShowConstraintsToggle(int theType, bool theState);
-
-private slots:
/// Process the enter mouse to the view port. If the current operation is a create of
/// a nested sketch feature, it updates internal flags to display the feature on mouse move
void onEnterViewPort();
}
return anAttribute;
}
+
+void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
+ const Events_ID theEventId)
+{
+ if (!theComposite.get())
+ return;
+
+ static Events_Loop* aLoop = Events_Loop::loop();
+ for (int i = 0; i < theComposite->numberOfSubs(); i++) {
+ FeaturePtr aSubFeature = theComposite->subFeature(i);
+ static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+ aECreator->sendUpdated(aSubFeature, theEventId);
+ }
+ Events_Loop::loop()->flush(theEventId);
+}
#include <ModelAPI_Object.h>
#include <ModelAPI_Attribute.h>
+#include <Events_Message.h>
+
#include <TopoDS_Shape.hxx>
#include <memory>
{
Geometrical = 0, // all constrains excepting dimensional
Dimensional, // lenght, distance, radius and angle constraints
+ Expressions, // parameter text should be shown in dimensional constraint
Any // both, geometrical and dimensional, types of constraints
};
* \param theStartCoin the coincedence feature
*/
static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
+
+ /// Sends redisplay event for all sub-features of the composite. Flush it.
+ static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
+ const Events_ID theId);
};
#endif
QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
+ aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
aLast = aStates.end();
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Circle.h>
+#include <SketcherPrs_Tools.h>
+
#include <Events_Error.h>
+#include <Events_Loop.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt.h>
SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
SetDimensionAspect(myAspect);
+
+ Events_Loop* aLoop = Events_Loop::loop();
+ const Events_ID kDocCreatedEvent =
+ SketcherPrs_ParameterStyleMessage::eventId();
+ aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
+}
+
+SketcherPrs_LengthDimension::~SketcherPrs_LengthDimension()
+{
+ Events_Loop* aLoop = Events_Loop::loop();
+ aLoop->removeListener(this);
+}
+
+void SketcherPrs_LengthDimension::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
+ if (theMessage->eventID() == kParameterStyleEvent) {
+ std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
+ SketcherPrs_ParameterStyleMessage>(theMessage);
+ myStyle = aMessage->style();
+ }
}
bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
- SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0);
-
+ bool aHasParameters = aValue->usedParameters().size() > 0;
+ if (aHasParameters) {
+ bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue;
+ SketcherPrs_Tools::setDisplaySpecialSymbol(this, isParameterValueStyle);
+ SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), !isParameterValueStyle);
+ }
+ else {
+ SketcherPrs_Tools::setDisplaySpecialSymbol(this, false);
+ SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), false);
+ }
AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
}
#include <AIS_LengthDimension.hxx>
#include <Standard_DefineHandle.hxx>
+#include <SketcherPrs_Tools.h>
+
+#include <Events_Listener.h>
+
DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension)
* A class for representation of linear dimension constraint.
* It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
*/
-class SketcherPrs_LengthDimension : public AIS_LengthDimension
+class SketcherPrs_LengthDimension : public AIS_LengthDimension, public Events_Listener
{
public:
/// Constructor
Standard_EXPORT SketcherPrs_LengthDimension(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+ /// Destructor
+ Standard_EXPORT ~SketcherPrs_LengthDimension();
+
DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension)
+ /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document
+ /// from the message with origin and planes
+ virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
/// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
/// \param theConstraint a constraint feature
/// \param thePlane a coordinate plane of current sketch
std::shared_ptr<GeomAPI_Ax3> myPlane;
Handle(Prs3d_DimensionAspect) myAspect;
+
+ /// Style how the parameter of dimension should be visualized
+ SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle;
};
#endif
\ No newline at end of file
}
}
+void setDisplayParameter(AIS_Dimension* theDimension, const std::string& theParameter,
+ const bool& theToDisplay)
+{
+ if (theToDisplay) {
+ theDimension->DimensionAspect()->MakeUnitsDisplayed(true);
+ theDimension->SetDisplayUnits(TCollection_AsciiString(theParameter.c_str()));
+ theDimension->DimensionAspect()->SetValueStringFormat("");
+ }
+ else {
+ theDimension->DimensionAspect()->MakeUnitsDisplayed(false);
+ theDimension->SetDisplayUnits(TCollection_AsciiString()); // THE_UNDEFINED_UNITS in AIS_Dimension
+ theDimension->DimensionAspect()->SetValueStringFormat("%g");
+ }
+}
+
+void sendExpressionShownEvent(const bool& theState)
+{
+ static Events_ID anId = SketcherPrs_ParameterStyleMessage::eventId();
+ std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::shared_ptr
+ <SketcherPrs_ParameterStyleMessage>(new SketcherPrs_ParameterStyleMessage(anId, 0));
+ aMessage->setStyle(theState ? SketcherPrs_ParameterStyleMessage::ParameterText
+ : SketcherPrs_ParameterStyleMessage::ParameterValue);
+ Events_Loop::loop()->send(aMessage);
+ Events_Loop::loop()->flush(anId);
+}
+
};
#include <ModelAPI_Feature.h>
#include <string>
+#include <Events_Loop.h>
+#include <Events_Message.h>
+
class GeomDataAPI_Point2D;
class AIS_Dimension;
//#define MyTextHeight 20
+/// Message that document (Part, PartSet) was created
+class SketcherPrs_ParameterStyleMessage : public Events_Message
+{
+public:
+ enum ParameterStyle {
+ ParameterValue, /// using symbol with the parameter value
+ ParameterText /// using parameter text
+ };
+
+public:
+ /// Creates an empty message
+ SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID,
+ const void* theSender = 0)
+ : Events_Message(theID, theSender) {}
+ /// The virtual destructor
+ SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {}
+ /// Static. Returns EventID of the message.
+ SKETCHERPRS_EXPORT static Events_ID eventId()
+ {
+ static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
+ return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
+ }
+ /// Returns a document stored in the message
+ SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; }
+ /// Sets a document to the message
+ SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; }
+private:
+ ParameterStyle myStyle; /// style of the parameter visualization
+};
+
namespace SketcherPrs_Tools {
/// Enumeration with modes for activation of selection custom presentations
ANGLE_BACKWARD ///< Angle from the second line to the first line
};
+ /// Event ID about expression visual state has been changed, the symbol with a digit
+ /// or parameter text is shown
+
/// Returns attribute object referenced by feature
/// \param theFeature a feature
/// \param theAttrName an attribute name
/// \param theToDisplay a boolean value
SKETCHERPRS_EXPORT void setDisplaySpecialSymbol(AIS_Dimension* theDimension,
const bool& theToDisplay);
+
+ /// Display the parameter value instead of dimention digit
+ /// \param theDimension a dimension constraint
+ /// \param theParameter a parameter value
+ /// \param theToDisplay a boolean value
+ SKETCHERPRS_EXPORT void setDisplayParameter(AIS_Dimension* theDimension,
+ const std::string& theParameter,
+ const bool& theToDisplay);
+
+ /// Sends event about expression visualization type is changed for dimension presentations
+ /// Sends event to redisplay all sub-features of composite feature
+ /// \param theState a new state
+ SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
+
};
#endif