#include <ModelAPI_Attribute.h>\r
\r
#include <GeomAPI_Shape.h>\r
+#include <GeomAPI_ICustomPrs.h>\r
\r
#include <QString>\r
#include <QObject>\r
virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,\r
const bool theUpdateViewer) {}\r
\r
+ /// Modifies the given presentation in the custom way.\r
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,\r
+ GeomCustomPrsPtr theCustomPrs) { return false; };\r
+\r
/// Update the object presentable properties such as color, lines width and other\r
/// If the object is result with the color attribute value set, it is used,\r
/// otherwise the customize is applyed to the object's feature if it is a custom prs\r
#include <XGUI_SelectionMgr.h>
#include <XGUI_DataModel.h>
#include <XGUI_ErrorMgr.h>
+#include <XGUI_CustomPrs.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
myCustomPrs->deactivate(theFlag, theUpdateViewer);
}
+bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+ bool aCustomized = false;
+
+ if (theResult.get())
+ return aCustomized;
+
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ ObjectPtr anObject = aDisplayer->getObject(thePrs);
+ if (anObject.get()) {
+ bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
+ // customize sketcy symbol presentation
+ if (thePrs.get()) {
+ Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
+ if (!anAISIO.IsNull()) {
+ 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);
+ aCustomized = true;
+ }
+ }
+ }
+ }
+ // customize sketch dimension constraint presentation
+ if (!aCustomized) {
+ std::vector<int> aColor;
+ if (isConflicting) {
+ myOverconstraintListener->getConflictingColor(aColor);
+ }
+ if (aColor.empty())
+ XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+ if (!aColor.empty()) {
+ thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+ aCustomized = true;
+ }
+ }
+ }
+
+ return aCustomized;
+}
+
bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
const bool theUpdateViewer)
{
virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
const bool theUpdateViewer);
+ /// Modifies the given presentation in the custom way.
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+
/// Update the object presentable properties such as color, lines width and other
/// If the object is result with the color attribute value set, it is used,
/// otherwise the customize is applyed to the object's feature if it is a custom prs
const std::set<ObjectPtr>& theConflictingObjects)
{
std::set<ObjectPtr> aModifiedObjects;
+ 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 anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end();
for (; anIt != aLast; anIt++) {
ObjectPtr anObject = *anIt;
if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found
- setConflictingObject(anObject, true);
aModifiedObjects.insert(anObject);
myConflictingObjects.insert(anObject);
}
for (anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end() ; anIt != aLast; anIt++) {
ObjectPtr anObject = *anIt;
if (theConflictingObjects.find(anObject) != theConflictingObjects.end()) { // it is found
- setConflictingObject(anObject, false);
myConflictingObjects.erase(anObject);
aModifiedObjects.insert(anObject);
aDisplayer->updateViewer();
}
-void PartSet_OverconstraintListener::setConflictingObject(const ObjectPtr& theObject,
- const bool theConflicting)
-{
- if (!theObject.get() || !theObject->data()->isValid())
- return;
-
- AISObjectPtr anAISObject;
- GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
-
- if (aPrs.get() != NULL) {
- XGUI_Workshop* aWorkshop = workshop();
- XGUI_Displayer* aDisplayer = aWorkshop->displayer();
-
- anAISObject = aPrs->getAISObject(aDisplayer->getAISObject(theObject));
- if (anAISObject.get()) {
- Handle(AIS_InteractiveObject) anAISIO = anAISObject->impl<Handle(AIS_InteractiveObject)>();
- if (!anAISIO.IsNull()) {
- if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
- Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
- if (!aPrs.IsNull())
- aPrs->SetConflictingConstraint(theConflicting);
- }
- }
- }
- }
-}
-
XGUI_Workshop* PartSet_OverconstraintListener::workshop() const
{
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
/// \return boolean value whether the list differs from the internal list
bool repairConflictingObjects(const std::set<ObjectPtr>& theObjects);
- /// Obtains the object custom AIS presentation and change conflicting state if it exists
- /// \param theObject the object which presentation error state should be changed
- /// \param theConflicting if true, the object state is erroneous, else correct
- void setConflictingObject(const ObjectPtr& theObject, const bool theConflicting);
-
/// Sends update object signal for each object in the container and flush it.
/// \param theObjects a list of object to be redisplayed
void redisplayObjects(const std::set<ObjectPtr>& theObjects);
/// Step between icons
static const double MyDist = 0.02;
+//#define ICON_TO_DEBUG
+
/// Function to convert opengl data type
GLenum toGlDataType (const Graphic3d_TypeOfData theType, GLint& theNbComp)
{
Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
{
+#ifdef ICON_TO_DEBUG
if (myIsConflicting) {
if (myErrorIcon.IsNull()) {
char* aEnv = getenv("NEWGEOM_ROOT_DIR");
}
return myErrorIcon;
}
+#endif
if (myIconsMap.count(iconName()) == 1) {
return myIconsMap[iconName()];
void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode)
+ const Standard_Integer aMode)
{
ClearSelected();
if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
}
}
-void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting)
+void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting,
+ const std::vector<int>& theColor)
{
+#ifdef ICON_TO_DEBUG
if (myIsConflicting != theConflicting) {
myIsConflicting = theConflicting;
Handle(Image_AlienPixMap) anIcon = icon();
if (!anIcon.IsNull())
myAspect->SetMarkerImage(new Graphic3d_MarkerImage(anIcon));
}
+#else
+ if (theConflicting)
+ {
+ if (!myAspect.IsNull())
+ myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
+ Quantity_TOC_RGB));
+ myIsConflicting = true;
+ }
+ else
+ {
+ if (!myAspect.IsNull())
+ myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB));
+ myIsConflicting = false;
+ }
+#endif
}
void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
{
+ // this method is a combination of OCCT OpenGL functions. The main purpose is to have
+ // equal distance from the source object to symbol indpendently of zoom.
+ // It is base on OCCT 6.9.1 and might need changes when using later OCCT versions.
+ // The specific SHAPER modifications are marked by ShaperModification:start/end, other is OCCT code
+
// do not update presentation for invalid or already removed objects: the presentation
// should be removed soon
if (!myConstraint->data().get() || !myConstraint->data()->isValid())
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
Handle(OpenGl_View) aView = theWorkspace->ActiveView();
+ // ShaperModification:start
double aScale = aView->Camera()->Scale();
// Update points coordinate taking the viewer scale into account
if (!updatePoints(MyDist * aScale))
return;
+ // ShaperModification:end
Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes();
const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx);
if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) {
+#ifdef ICON_TO_DEBUG
const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0;
+#else
+ // ShaperModification:start : filling the presentation with color if there is a conflict
+ const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0 || myIsConflicting;
+ // ShaperModification:end
+#endif
+
const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid())
? anAspectMarker->SpriteHighlightRes(aCtx)
: aSpriteNorm;
/// 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
- Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting);
+ /// \param theColor a color for conflicting object
+ Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting, const std::vector<int>& theColor);
/// Render of the presentation
/// \param theWorkspace is OpenGl workspace
}
}
-void getDefaultColor(ObjectPtr theObject, std::vector<int>& theColor, const bool isEmptyColorValid)
+void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+ std::vector<int>& theColor)
{
theColor.clear();
// get default color from the preferences manager for the given result
{
getColor(theResult, theColor);
if (theColor.empty())
- getDefaultColor(theResult, theColor, false);
+ getDefaultColor(theResult, false, theColor);
}
bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
}
else {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- ObjectPtr anObject = aDisplayer->getObject(thePrs);
- if (anObject.get()) {
- std::vector<int> aColor;
- ModuleBase_IModule* aModule = myWorkshop->module();
- aModule->getColor(anObject, aColor);
- if (aColor.empty())
- getDefaultColor(anObject, aColor, true);
- if (!aColor.empty())
- thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+ if (!aCustomized) {
+ ModuleBase_IModule* aModule = myWorkshop->module();
+ aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs);
}
}
return aCustomized;
/// \param theColor a color in form of RGB vector
static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
+ /// Returns the default object color. It obtains colorConfigInfo of the object
+ /// and find it in preferences. If there are no this color in preference and an empty
+ /// color is interpreted as invalid, it shows error message
+ /// \param theObject an investigated object
+ /// \param isEmptyColorValid boolean state about interpretation of empty color
+ /// \param theColor the result color
+ static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+ std::vector<int>& theColor);
+
+
protected:
XGUI_Workshop* myWorkshop; /// the current workshop
};