public:\r
/// enumeration to know which objects should be customized\r
enum ModuleBase_CustomizeFlag {\r
- CustomizeDependedAndResults = 0x00000000,\r
- CustomizeHighlightedObjects = 0x00000001\r
+ CustomizeArguments = 0, /// references of other objects referenced to the current feature\r
+ CustomizeResults, /// results of the current feature\r
+ CustomizeHighlightedObjects /// highlighted objects of the active widget\r
};\r
\r
/// Constructor\r
//#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
- : myWorkshop(theWorkshop), myIsActive(false)
+ : myWorkshop(theWorkshop), myIsActive(false), myFeature(FeaturePtr())
{
- initPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
+ initPresentation(ModuleBase_IModule::CustomizeArguments);
+ initPresentation(ModuleBase_IModule::CustomizeResults);
initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
}
#endif
myIsActive = true;
-
+ myFeature = theFeature;
bool isModified = false;
- getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(theFeature);
- getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(theFeature);
if (theFeature.get()) {
- displayPresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
isModified = true;
}
myIsActive = false;
bool isModified = false;
- getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(FeaturePtr());
- getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(FeaturePtr());
-
- erasePresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
isModified = true;
return isModified;
}
-bool PartSet_CustomPrs::displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
- const bool theUpdateViewer)
+bool PartSet_CustomPrs::displayPresentation(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
bool isModified = false;
+
+ // update the AIS objects content
Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
- if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
- PartSet_OperationPrs::getFeatureShapes(anOperationPrs->getFeature(), myWorkshop,
- anOperationPrs->featureShapes());
- anOperationPrs->updateShapes();
- }
- else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
- PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
+ // do nothing if the feature can not be displayed [is moved from presentation, to be checked]
+ if (!myFeature.get() || !myWorkshop->module()->canDisplayObject(myFeature))
+ return isModified;
+
+ switch (theFlag) {
+ case ModuleBase_IModule::CustomizeArguments:
+ PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+ break;
+ case ModuleBase_IModule::CustomizeResults:
+ PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+ break;
+ case ModuleBase_IModule::CustomizeHighlightedObjects:
+ PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
+ break;
+ default:
+ return isModified;
}
+ // redisplay AIS objects
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
if (anOperationPrs->hasShapes()) {
// set color here because it can be changed in preferences
- Quantity_Color aShapeColor, aResultColor;
- getAISColors(theFlag, aShapeColor, aResultColor);
- anOperationPrs->setColors(aShapeColor, aResultColor);
+ Quantity_Color aShapeColor = getShapeColor(theFlag);
+ anOperationPrs->setShapeColor(aShapeColor);
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
XGUI_Workshop* aWorkshop = workshop();
void PartSet_CustomPrs::clearPrs()
{
- clearPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
+ clearPresentation(ModuleBase_IModule::CustomizeArguments);
+ clearPresentation(ModuleBase_IModule::CustomizeResults);
clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
}
AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
- if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
+ if (theFlag == ModuleBase_IModule::CustomizeArguments ||
+ theFlag == ModuleBase_IModule::CustomizeResults) {
anOperationPrs->setPointMarker(5, 2.);
anOperationPrs->setWidth(1);
}
- else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
+ else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
anAISPrs->useAISWidth();
- }
if (anOperationPrs.get())
myPresentations[theFlag] = anOperationPrs;
}
-void PartSet_CustomPrs::getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
- Quantity_Color& theShapeColor, Quantity_Color& theResultColor)
+Quantity_Color PartSet_CustomPrs::getShapeColor(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
{
- if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
- theShapeColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
- OPERATION_PARAMETER_COLOR());
- theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
- OPERATION_RESULT_COLOR());
- }
- else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
- theShapeColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
- OPERATION_HIGHLIGHT_COLOR());
- theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
- OPERATION_RESULT_COLOR());
+ Quantity_Color aColor;
+ switch(theFlag) {
+ case ModuleBase_IModule::CustomizeArguments:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
+ OPERATION_PARAMETER_COLOR());
+ break;
+ case ModuleBase_IModule::CustomizeResults:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
+ OPERATION_RESULT_COLOR());
+ break;
+ case ModuleBase_IModule::CustomizeHighlightedObjects:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
+ OPERATION_HIGHLIGHT_COLOR());
+ break;
+ default:
+ break;
}
+ return aColor;
}
XGUI_Workshop* PartSet_CustomPrs::workshop() const
/// \param theFlag an object AIS presentation type
void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
- /// Returns presentation colors according to the flag
+ /// Returns presentation color according to the flag
/// \param theFlag an object AIS presentation type
- /// \param theShapeColor a color for shapes
- /// \param theShapeColor a color for results
- void getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
- Quantity_Color& theShapeColor, Quantity_Color& theResultColor);
+ /// \return theShapeColor a color
+ Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
private:
- bool myIsActive;
+ bool myIsActive; /// State whether the presentation is activated/deactivated
+ FeaturePtr myFeature; /// Reference to a feature object
ModuleBase_IWorkshop* myWorkshop; /// current workshop
/// map of presentation type to AIS object
QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
#include <QList>
+static const int AIS_DEFAULT_WIDTH = 2;
+
IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape);
IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape);
PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
-: ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop),
- myUseAISWidth(false)
-{
- myShapeColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "1,1,0");
- myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0");
-}
-
-void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature)
-{
- myFeature = theFeature;
-}
-
-void PartSet_OperationPrs::updateShapes()
+: ViewerData_AISShape(TopoDS_Shape()), myWorkshop(theWorkshop), myUseAISWidth(false)
{
- myFeatureResults.clear();
- if (myFeature)
- myFeatureResults = myFeature->results();
+ myShapeColor = Quantity_Color(1, 1, 1, Quantity_TOC_RGB);
}
bool PartSet_OperationPrs::hasShapes()
{
- bool aHasShapes = !myFeatureShapes.empty();
-
- // find a result which contains a shape
- if (!aHasShapes && !myFeatureResults.empty()) {
- std::list<ResultPtr>::const_iterator aRIt = myFeatureResults.begin(),
- aRLast = myFeatureResults.end();
- XGUI_Displayer* aDisplayer = workshop()->displayer();
- for (; aRIt != aRLast; aRIt++) {
- ResultPtr aResult = *aRIt;
- if (!isVisible(aDisplayer, aResult))
- continue;
- GeomShapePtr aGeomShape = aResult->shape();
- if (!aGeomShape.get())
- continue;
- TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
- if (!aShape.IsNull())
- aHasShapes = true;
- }
- }
-
- return aHasShapes;
+ return !myFeatureShapes.empty();
}
-void PartSet_OperationPrs::setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor)
+void PartSet_OperationPrs::setShapeColor(const Quantity_Color& theColor)
{
- myShapeColor = theShapeColor;
- myResultColor = theResultColor;
+ myShapeColor = theColor;
}
void PartSet_OperationPrs::useAISWidth()
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
- if (!hasShapes())
- return;
- // when the feature can not be visualized in the module, the operation preview should not
- // be visualized also
- if (!myWorkshop->module()->canDisplayObject(myFeature))
- return;
-
SetColor(myShapeColor);
thePresentation->Clear();
- XGUI_Displayer* aDisplayer = workshop()->displayer();
+ XGUI_Displayer* aDisplayer = workshop(myWorkshop)->displayer();
Handle(Prs3d_Drawer) aDrawer = Attributes();
// create presentations on the base of the shapes
AISObjectPtr anAISPtr = aDisplayer->getAISObject(anObject);
if (anAISPtr.get()) {
Handle(AIS_InteractiveObject) anIO = anAISPtr->impl<Handle(AIS_InteractiveObject)>();
- if (!anIO.IsNull())
- setWidth(aDrawer, anIO->Width());
+ if (!anIO.IsNull()) {
+ int aWidth = anIO->Width();
+ /// workaround for zero width. Else, there will be a crash
+ if (aWidth == 0) { // width returns of TSolid shape is zero
+ bool isDisplayed = !anIO->GetContext().IsNull();
+ aWidth = AIS_DEFAULT_WIDTH;// default width value
+ }
+ setWidth(aDrawer, aWidth);
+ }
}
}
StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
}
}
-
- // create presentations on the base of the results
- SetColor(myResultColor);
- std::list<ResultPtr>::const_iterator aRIt = myFeatureResults.begin(),
- aRLast = myFeatureResults.end();
- for (; aRIt != aRLast; aRIt++) {
- ResultPtr aResult = *aRIt;
- if (!isVisible(aDisplayer, aResult))
- continue;
- GeomShapePtr aGeomShape = aResult->shape();
- if (!aGeomShape.get())
- continue;
- TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
- // change deviation coefficient to provide more precise circle
- ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer);
- StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
- }
- QList<ModuleBase_ViewerPrs> aValues;
- ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel();
- if (aPanel) {
- ModuleBase_ModelWidget* aWidget = aPanel->activeWidget();
- if (aWidget) {
- aWidget->getHighlighted(aValues);
- }
- }
}
void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
}
}
+void PartSet_OperationPrs::getResultShapes(const FeaturePtr& theFeature,
+ ModuleBase_IWorkshop* theWorkshop,
+ QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
+{
+ theObjectShapes.clear();
+
+ if (!theFeature.get())
+ return;
+
+ XGUI_Displayer* aDisplayer = workshop(theWorkshop)->displayer();
+
+ std::list<ResultPtr> aFeatureResults = theFeature->results();
+ std::list<ResultPtr>::const_iterator aRIt = aFeatureResults.begin(),
+ aRLast = aFeatureResults.end();
+ for (; aRIt != aRLast; aRIt++) {
+ ResultPtr aResult = *aRIt;
+ if (!isVisible(aDisplayer, aResult))
+ continue;
+ GeomShapePtr aGeomShape = aResult->shape();
+ if (!aGeomShape.get())
+ continue;
+
+ if (theObjectShapes.contains(aResult))
+ theObjectShapes[aResult].append(aGeomShape);
+ else {
+ QList<GeomShapePtr> aShapes;
+ aShapes.append(aGeomShape);
+ theObjectShapes[aResult] = aShapes;
+ }
+ }
+}
+
void PartSet_OperationPrs::getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop,
QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
{
anAttrType == ModelAPI_AttributeReference::typeId();
}
-XGUI_Workshop* PartSet_OperationPrs::workshop() const
+XGUI_Workshop* PartSet_OperationPrs::workshop(ModuleBase_IWorkshop* theWorkshop)
{
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
return aConnector->workshop();
}
/// Constructor
Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
- /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes
- /// theFeature a feature
- void setFeature(const FeaturePtr& theFeature);
-
- // Recompute internal list of shaped dependent on the current feature
- void updateShapes();
-
/// Returns true if the feature contains shapes or results
bool hasShapes();
/// Sets the colors for the presentation compute
- /// \param theShapeColor an argument shapes color
- /// \param theResultColor a color for operation result
- void setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor);
+ /// \param theColor an argument shapes color
+ void setShapeColor(const Quantity_Color& theColor);
/// Switch on using of the AIS presentation with of the shape object increased on the delta
void useAISWidth();
const Standard_Integer aMode) ;
protected:
- /// Reference to a feature object
- FeaturePtr getFeature() { return myFeature; }
-
/// Returns map of feature shapes to be able to fill it outside this class, e.g. in friend
/// \return a map of object to shape
QMap<ObjectPtr, QList<GeomShapePtr> >& featureShapes() { return myFeatureShapes; }
/// \param theDisplayer a displayer
/// \param theObject an object
/// \return a boolean value
- bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
+ static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
/// Fills the map by the feature object and shapes, which should be visuaziled
/// Gets feature attributes, collect objects to whom the attributes refer
ModuleBase_IWorkshop* theWorkshop,
QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
+ /// Fills the map by the feature object and shapes, which should be visuaziled
+ /// Gets feature attributes, collect objects to whom the attributes refer
+ /// \param theFeature a current feature
+ /// \param theWorkshop a current workshop
+ /// \param theObjectShapes an output map
+ /// \param theObjectShape an output map of objects
+ static void getResultShapes(const FeaturePtr& theFeature,
+ ModuleBase_IWorkshop* theWorkshop,
+ QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
+
/// Fills the map by the feature object and shapes, which should be visuaziled
/// Gets the active widget, obtain the highlighted presentations if it has such and
/// fill map by object and shapes
static bool isSelectionAttribute(const AttributePtr& theAttribute);
/// Converts the current workshop to XGUI workshop
+ /// \param theWorkshop an interface workshop
/// \return a workshop instance
- XGUI_Workshop* workshop() const;
+ static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
private:
- ModuleBase_IWorkshop* myWorkshop;
- FeaturePtr myFeature; /// Reference to a feature object
QMap<ObjectPtr, QList<GeomShapePtr> > myFeatureShapes; /// visualized shapes
- std::list<ResultPtr> myFeatureResults; /// visualized feature results
+ ModuleBase_IWorkshop* myWorkshop; /// current workshop
Quantity_Color myShapeColor; /// color of feature depended shapes
- Quantity_Color myResultColor; /// color of feature result
-
bool myUseAISWidth; /// flag if the width of a shape object should be used for the shape visualization
friend class PartSet_CustomPrs;
// e.g. extrusion is hidden(h=0) but sketch is chosen
if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) {
aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
- ModuleBase_IModule::CustomizeDependedAndResults, false);
+ ModuleBase_IModule::CustomizeArguments, false);
+ aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
+ ModuleBase_IModule::CustomizeResults, false);
aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
ModuleBase_IModule::CustomizeHighlightedObjects, false);
}