return aCustomized;
if (!theResult.get()) {
- bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
+ std::vector<int> aColor;
+ bool isConflicting = myOverconstraintListener->hasCustomColor(anObject, aColor);
// customize sketch symbol presentation
if (thePrs.get()) {
Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
if (!aPrs.IsNull()) {
- std::vector<int> aColor;
- myOverconstraintListener->getConflictingColor(aColor);
- aPrs->SetConflictingConstraint(isConflicting, aColor);
+ aPrs->SetCustomColor(aColor);
aCustomized = true;
}
} else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
if (!aPrs.IsNull()) {
- std::vector<int> aColor;
- myOverconstraintListener->getConflictingColor(aColor);
- aPrs->SetConflictingConstraint(isConflicting, aColor);
+ aPrs->SetCustomColor(aColor);
aCustomized = true;
}
}
}
// customize sketch dimension constraint presentation
if (!aCustomized) {
- std::vector<int> aColor;
- if (isConflicting) {
- myOverconstraintListener->getConflictingColor(aColor);
- }
- if (aColor.empty())
+ if (!isConflicting)
XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
if (!aColor.empty()) {
aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
// Created: 20 August 2015
// Author: Vitaly SMETANNIKOV
+#include <ModelAPI_Tools.h>
+
#include "PartSet_OverconstraintListener.h"
+#include <PartSet_Module.h>
+#include <PartSet_SketcherMgr.h>
#include "XGUI_ModuleConnector.h"
#include "XGUI_Workshop.h"
#include "XGUI_Displayer.h"
+#include "XGUI_CustomPrs.h"
#include "SketcherPrs_SymbolPrs.h"
#include "SketchPlugin_SketchEntity.h"
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED));
-}
-bool PartSet_OverconstraintListener::isConflictingObject(const ObjectPtr& theObject)
-{
- return myConflictingObjects.find(theObject) != myConflictingObjects.end();
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED));
}
-void PartSet_OverconstraintListener::getConflictingColor(std::vector<int>& theColor)
+bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject,
+ std::vector<int>& theColor)
{
- Quantity_Color aColor = ModuleBase_Tools::color("Visualization", "sketch_overconstraint_color");
- theColor.push_back(aColor.Red()*255.);
- theColor.push_back(aColor.Green()*255.);
- theColor.push_back(aColor.Blue()*255.);
+ if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
+ Quantity_Color aColor = ModuleBase_Tools::color("Visualization",
+ "sketch_overconstraint_color");
+ theColor.push_back(aColor.Red()*255.);
+ theColor.push_back(aColor.Green()*255.);
+ theColor.push_back(aColor.Blue()*255.);
+ return true;
+ }
+ if (myIsFullyConstrained) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get()) {
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch();
+ // the given object is sub feature of the current sketch(created or edited)
+ if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) {
+ Quantity_Color aColor = ModuleBase_Tools::color("Visualization",
+ "sketch_fully_constrained_color");
+ theColor.push_back(aColor.Red()*255.);
+ theColor.push_back(aColor.Green()*255.);
+ theColor.push_back(aColor.Blue()*255.);
+ return true;
+ }
+ }
+ }
+ return false;
}
void PartSet_OverconstraintListener::processEvent(
.arg(aCurrentInfoStr).toStdString().c_str());
#endif
- if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) {
+ Events_ID anEventID = theMessage->eventID();
+ if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED) ||
+ anEventID == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)) {
std::shared_ptr<ModelAPI_SolverFailedMessage> anErrorMsg =
std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
bool anUpdated = false;
if (anErrorMsg.get()) {
const std::set<ObjectPtr>& aConflictingObjects = anErrorMsg->objects();
- anUpdated = appendConflictingObjects(aConflictingObjects);
- }
- else {
- // there is a crash in the solver. All objects are invalid
- //anUpdated = appendConflictingObjects(std::set<ObjectPtr>());
+ if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED))
+ anUpdated = appendConflictingObjects(aConflictingObjects);
+ else
+ anUpdated = repairConflictingObjects(aConflictingObjects);
}
}
- if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)) {
- std::shared_ptr<ModelAPI_SolverFailedMessage> anErrorMsg =
- std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
- bool anUpdated = false;
- if (anErrorMsg.get()) {
- const std::set<ObjectPtr>& aConflictingObjects = anErrorMsg->objects();
- anUpdated = repairConflictingObjects(aConflictingObjects);
- }
- else {
- // there is no repaired objects, do nothing
- }
+ else if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) ||
+ anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)) {
+ myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED);
}
#ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
const std::set<ObjectPtr>& theConflictingObjects)
{
std::set<ObjectPtr> aModifiedObjects;
- std::vector<int> aColor;
- getConflictingColor(aColor);
+ //std::vector<int> aColor;
+ //getConflictingColor(aColor);
// set error state for new objects and append them in the internal map of objects
std::set<ObjectPtr>::const_iterator
/// Returns true if the object belongs to internal container of conflicting objects
/// \param theObject an object to be checked
- /// \return boolean result
- bool isConflictingObject(const ObjectPtr& theObject);
-
- /// Returns values of conflicting color
/// \param theColor the output container to be filled in [red, green, blue] values
- void getConflictingColor(std::vector<int>& theColor);
+ /// \return boolean result
+ bool hasCustomColor(const ObjectPtr& theObject, std::vector<int>& theColor);
/// Redefinition of Events_Listener method
virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
private:
std::set<ObjectPtr> myConflictingObjects;
ModuleBase_IWorkshop* myWorkshop;
+ bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
};
#endif
#include <iostream>
#endif
+#define SKETCH_ENTITY_COLOR "225,0,0"
+#define SKETCH_EXTERNAL_COLOR "170,0,225"
+#define SKETCH_AUXILIARY_COLOR "0,85,0"
+#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
+#define SKETCH_FULLY_CONSTRAINED_COLOR "150,150,150"
+
//#define SET_PLANES_COLOR_IN_PREFERENCES
// the only created instance of this plugin
"Sketch overconstraint color",
Config_Prop::Color, SKETCH_OVERCONSTRAINT_COLOR);
+ Config_PropManager::registerProp("Visualization", "sketch_fully_constrained_color",
+ "Sketch fully constrained color",
+ Config_Prop::Color, SKETCH_FULLY_CONSTRAINED_COLOR);
+
// register sketcher properties
#ifdef SET_PLANES_COLOR_IN_PREFERENCES
Config_PropManager::registerProp("Visualization", "yz_plane_color", "YZ plane color",
#include <Config_PropManager.h>
-#define SKETCH_ENTITY_COLOR "225,0,0"
-#define SKETCH_EXTERNAL_COLOR "170,0,225"
-#define SKETCH_AUXILIARY_COLOR "0,85,0"
-#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
-
/**\class SketchPlugin_SketchEntity
* \ingroup Plugins
* \brief Sketch Entity for creation of the new feature in PartSet.
SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
: AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
- myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsConflicting(false)
+ myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
{
}
myPoint = aPoint;
// Create the presentation as a combination of standard point markers
- bool aValid = !myIsConflicting;
+ bool aCustomColor = myIsCustomColor;
// The external yellow contour
Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
aPtA->SetType(Aspect_TOM_RING3);
aPtA->SetScale(2.);
- aPtA->SetColor(aValid ? Quantity_NOC_YELLOW : myConflictingColor);
+ aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor);
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
aGroup->SetPrimitivesAspect(aPtA);
aPtA = new Graphic3d_AspectMarker3d();
aPtA->SetType(Aspect_TOM_RING1);
aPtA->SetScale(1.);
- aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor);
+ aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
aGroup->SetPrimitivesAspect(aPtA);
aGroup->AddPrimitiveArray (aPntArray);
aPtA = new Graphic3d_AspectMarker3d();
aPtA->SetType(Aspect_TOM_POINT);
aPtA->SetScale(5.);
- aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor);
+ aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
aGroup->SetPrimitivesAspect(aPtA);
aGroup->AddPrimitiveArray (aPntArray);
myOwnColor=aCol;
}
-void SketcherPrs_Coincident::SetConflictingConstraint(const bool& theConflicting,
- const std::vector<int>& theColor)
+void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
{
- myIsConflicting = theConflicting;
- myConflictingColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
- Quantity_TOC_RGB);
+ myIsCustomColor = !theColor.empty();
+ if (myIsCustomColor)
+ myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
+ theColor[2] / 255., Quantity_TOC_RGB);
+ else
+ myCustomColor = Quantity_Color();
}
/// \param aColor a color name
Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor);
- /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
+ /// Set state of the presentation, in case of custom color, the icon of the presentation is
/// visualized in error color.
- /// The state is stored in an internal field, so should be changed when
- /// constraint become not conflicting
- /// \param theConflicting a state
- /// \param theColor a color for conflicting object
- Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
- const std::vector<int>& theColor);
+ /// \param theColor a custom color for object presentation
+ Standard_EXPORT void SetCustomColor(const std::vector<int>& theColor);
/// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
/// \param theConstraint a constraint feature
ModelAPI_Feature* myConstraint;
std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
gp_Pnt myPoint;
- bool myIsConflicting; /// state if the presentation is visualized in error state
- Quantity_Color myConflictingColor; /// the color of mid ring if there is a conflict
+ bool myIsCustomColor; /// state if the presentation is visualized in custom color
+ Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict
};
SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
- : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsConflicting(false)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsCustomColor(false)
{
SetAutoHilight(Standard_False);
myPntArray = new Graphic3d_ArrayOfPoints(1);
else
myAspect = new Graphic3d_AspectMarker3d(aIcon);
- myAspect->SetColor(myColor);
+ myAspect->SetColor(myCustomColor);
}
}
}
//*********************************************************************************
-void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting,
- const std::vector<int>& theColor)
+void SketcherPrs_SymbolPrs::SetCustomColor(const std::vector<int>& theColor)
{
- if (theConflicting)
- {
- myColor = Quantity_Color (theColor[0] / 255., theColor[1] / 255.,
- theColor[2] / 255., Quantity_TOC_RGB);
- //if (!myAspect.IsNull())
- // myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255.,
- // theColor[2] / 255., Quantity_TOC_RGB));
- //myIsConflicting = true;
- }
+ myIsCustomColor = !theColor.empty();
+ if (myIsCustomColor)
+ myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
+ theColor[2] / 255., Quantity_TOC_RGB);
else
- {
- myColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB);
- //if (!myAspect.IsNull())
- // myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB));
- //myIsConflicting = false;
- }
+ myCustomColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB);
+
+ if (!myAspect.IsNull())
+ myAspect->SetColor (myCustomColor);
}
//*********************************************************************************
/// Set state of the presentation, in case of conflicting state, the icon of the presentation is
/// visualized in error color. The state is stored in an internal field, so should be changed
/// when constraint become not conflicting
- /// \param theConflicting a state
/// \param theColor a color for conflicting object
- Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
- const std::vector<int>& theColor);
+ Standard_EXPORT void SetCustomColor(const std::vector<int>& theColor);
/// Add a bounding box of the presentation to common bounding box
/// \param theBndBox the common bounding box to update
Select3D_EntitySequence mySPoints;
- Quantity_Color myColor;
- bool myIsConflicting; /// state if the presentation is visualized in error state
+ bool myIsCustomColor; /// state if the presentation is visualized in custom color
+ Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict
+
+ //Quantity_Color myIsCustomColor;
+ //bool myIsConflicting; /// state if the presentation is visualized in error state
Handle(Image_AlienPixMap) myErrorIcon;
Handle(Graphic3d_MarkerImage) myErrorImage;