Two classes TDataXtd_Presentation and TPrsStd_AISPresentation were improved so that they accept a list of selection modes.
A new non-regression test is added: caf presentation N1
//=======================================================================
//function : DPrsStd_AISSelMode
-//purpose : AISSelMode (DOC,entry,[SelMode])
+//purpose : AISSelMode (DOC,entry,[SelMode1 SelMode2 ...])
//=======================================================================
static Standard_Integer DPrsStd_AISSelMode(Draw_Interpretor& di,
Standard_Integer nb,
TDF_Label L;
Handle(TDocStd_Document) D;
Handle(TPrsStd_AISPresentation) prs;
- if (nb >= 3 && nb <= 4)
+ if (nb >= 3)
{
if (!DDocStd::GetDocument(arg[1],D))
return 1;
return 1;
if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(), prs))
return 1;
- if (nb == 4)
+ if (nb >= 4)
{
// Set selection mode.
Standard_Integer selMode = Draw::Atoi(arg[3]);
prs->SetSelectionMode(selMode);
+ // Add other selection modes.
+ for (Standard_Integer i = 4; i < nb; i++)
+ {
+ selMode = Draw::Atoi(arg[i]);
+ prs->AddSelectionMode(selMode);
+ }
TPrsStd_AISViewer::Update(L);
}
else if (nb == 3)
{
// Print selection mode.
- Standard_Integer selMode = prs->SelectionMode();
- di<<selMode;
+ Standard_Integer nbSelModes = prs->GetNbSelectionModes();
+ if (nbSelModes == 1)
+ {
+ Standard_Integer selMode = prs->SelectionMode();
+ di << selMode;
+ }
+ else
+ {
+ for (Standard_Integer i = 1; i <= nbSelModes; i++)
+ {
+ Standard_Integer selMode = prs->SelectionMode(i);
+ di << selMode;
+ if (i < nbSelModes)
+ di << " ";
+ }
+ }
}
return 0;
}
__FILE__, DPrsStd_AISMode, g);
theCommands.Add ("AISSelMode",
- "AISSelMode (DOC, entry, [SelMode])",
+ "AISSelMode (DOC, entry, [SelMode1 SelMode2 ...])",
__FILE__, DPrsStd_AISSelMode, g);
}
myColor (Quantity_NOC_WHITE),
myMaterialIndex (0),
myMode (0),
- mySelectionMode (0),
myTransparency (0.0),
myWidth (0.0),
myIsDisplayed (Standard_False),
}
}
+//=======================================================================
+//function : GetNbSelectionModes
+//purpose : Returns the number of selection modes of the attribute.
+// : It starts with 1 .. GetNbSelectionModes().
+//=======================================================================
+Standard_EXPORT Standard_Integer TDataXtd_Presentation::GetNbSelectionModes() const
+{
+ return mySelectionModes.Extent();
+}
//=======================================================================
//function : SetSelectionMode
//=======================================================================
void TDataXtd_Presentation::SetSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction)
{
- if (! myHasOwnSelectionMode || mySelectionMode != theSelectionMode)
+ if (!myHasOwnSelectionMode || GetNbSelectionModes() > 1 ||
+ (GetNbSelectionModes() > 0 && mySelectionModes.First() != theSelectionMode))
{
if (theTransaction)
- Backup();
- mySelectionMode = theSelectionMode;
+ Backup();
+ mySelectionModes.Clear();
+ mySelectionModes.Append(theSelectionMode);
myHasOwnSelectionMode = Standard_True;
}
}
+//=======================================================================
+//function : AddSelectionMode
+//purpose :
+//=======================================================================
+void TDataXtd_Presentation::AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction)
+{
+ if (!myHasOwnSelectionMode || !HasSelectionMode(theSelectionMode))
+ {
+ if (theTransaction)
+ Backup();
+ mySelectionModes.Append(theSelectionMode);
+ myHasOwnSelectionMode = Standard_True;
+ }
+}
//=======================================================================
//function : MaterialIndex
//function : SelectionMode
//purpose :
//=======================================================================
-Standard_Integer TDataXtd_Presentation::SelectionMode() const
+Standard_Integer TDataXtd_Presentation::SelectionMode(const Standard_Integer index) const
{
- return mySelectionMode;
+ Standard_Integer aSelectionMode(0);
+ TColStd_ListOfInteger::Iterator itr(mySelectionModes);
+ for (Standard_Integer i = 1; itr.More() && i <= index; itr.Next(), i++)
+ {
+ if (i == index)
+ aSelectionMode = itr.Value();
+ }
+ return aSelectionMode;
}
{
Backup();
myHasOwnSelectionMode = Standard_False;
+ mySelectionModes.Clear();
}
}
aCopy->myIsDisplayed = myIsDisplayed;
aCopy->myDriverGUID = myDriverGUID;
- aCopy->mySelectionMode = mySelectionMode;
+ aCopy->mySelectionModes= mySelectionModes;
aCopy->myTransparency = myTransparency;
aCopy->myColor = myColor;
aCopy->myMode = myMode;
myMode = aPresentation->Mode();
myHasOwnSelectionMode = aPresentation->HasOwnSelectionMode();
- mySelectionMode = aPresentation->SelectionMode();
+ mySelectionModes = aPresentation->mySelectionModes;
myHasOwnTransparency = aPresentation->HasOwnTransparency();
myTransparency = aPresentation->Transparency();
if (myHasOwnSelectionMode)
{
- anInto->mySelectionMode = mySelectionMode;
+ anInto->mySelectionModes = mySelectionModes;
anInto->myHasOwnSelectionMode = Standard_True;
}
else
anInto->myIsDisplayed = myIsDisplayed;
anInto->myDriverGUID = myDriverGUID;
}
+
+//=======================================================================
+//function : HasSelectionMode
+//purpose : Checks a list of selection modes.
+//=======================================================================
+Standard_Boolean TDataXtd_Presentation::HasSelectionMode(const Standard_Integer theSelectionMode) const
+{
+ Standard_Boolean ret(Standard_False);
+ TColStd_ListOfInteger::Iterator itr(mySelectionModes);
+ for (; itr.More(); itr.Next())
+ {
+ if (theSelectionMode == itr.Value())
+ ret = Standard_True;
+ }
+ return ret;
+}
#include <gp_Pnt.hxx>
#include <TDF_Attribute.hxx>
#include <Quantity_NameOfColor.hxx>
+#include <TColStd_ListOfInteger.hxx>
class TDF_Label;
class gp_Pnt;
Standard_EXPORT void SetMode(const Standard_Integer theMode);
+ //! Returns the number of selection modes of the attribute.
+ //! It starts with 1 .. GetNbSelectionModes().
+ Standard_EXPORT Standard_Integer GetNbSelectionModes() const;
+
//! Sets selection mode.
//! If "theTransaction" flag is OFF, modification of the attribute doesn't influence the transaction mechanism
- //! (the attribute doesn't participate in undo/redo).
+ //! (the attribute doesn't participate in undo/redo because of this modification).
//! Certainly, if any other data of the attribute is modified (display mode, color, ...),
- //! the attribute will be included into transaction.
- //! Obsolete method (may be removed later).
+ //! the attribute will be included into undo/redo.
Standard_EXPORT void SetSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
+ Standard_EXPORT void AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
Standard_EXPORT Standard_Integer MaterialIndex() const;
Standard_EXPORT Standard_Integer Mode() const;
- Standard_EXPORT Standard_Integer SelectionMode() const;
+ Standard_EXPORT Standard_Integer SelectionMode(const int index = 1) const;
Standard_EXPORT void UnsetMaterial();
Quantity_NameOfColor myColor;
Standard_Integer myMaterialIndex;
Standard_Integer myMode;
- Standard_Integer mySelectionMode;
+ TColStd_ListOfInteger mySelectionModes;
Standard_Real myTransparency;
Standard_Real myWidth;
Standard_Boolean myIsDisplayed;
Standard_Boolean myHasOwnWidth;
Standard_Boolean myHasOwnMode;
Standard_Boolean myHasOwnSelectionMode;
+
+ //! Checks a list of selection modes.
+ Standard_Boolean HasSelectionMode(const Standard_Integer theSelectionMode) const;
};
#endif // _TDataXtd_Presentation_HeaderFile
}
}
+//=======================================================================
+//function : GetNbSelectionModes
+//purpose : Returns selection mode(s) of the attribute.
+// : It starts with 1 .. GetNbSelectionModes().
+//=======================================================================
+Standard_Integer TPrsStd_AISPresentation::GetNbSelectionModes() const
+{
+ return getData()->GetNbSelectionModes();
+}
+
//=======================================================================
//function : SelectionMode
//purpose :
//=======================================================================
-Standard_Integer TPrsStd_AISPresentation::SelectionMode() const
+Standard_Integer TPrsStd_AISPresentation::SelectionMode(const Standard_Integer index) const
{
- return getData()->SelectionMode();
+ return getData()->SelectionMode(index);
}
//=======================================================================
ActivateSelectionMode();
}
+//=======================================================================
+//function : AddSelectionMode
+//purpose :
+//=======================================================================
+void TPrsStd_AISPresentation::AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction)
+{
+ if (theTransaction)
+ Backup();
+ getData()->AddSelectionMode (theSelectionMode, theTransaction);
+
+ if (myAIS.IsNull())
+ AISUpdate();
+ else
+ ActivateSelectionMode();
+}
+
//=======================================================================
//function : UnsetSelectionMode
//purpose :
//=======================================================================
void TPrsStd_AISPresentation::UnsetSelectionMode()
{
- getData()->UnsetSelectionMode ();
+ getData()->UnsetSelectionMode();
AISUpdate();
}
{
TColStd_ListOfInteger anActivatedModes;
aContext->ActivatedModes (myAIS, anActivatedModes);
- Standard_Boolean isActivated = Standard_False;
- Standard_Integer aSelectionMode = SelectionMode();
- if (aSelectionMode == -1)
+ Standard_Integer nbSelModes = GetNbSelectionModes();
+ if (nbSelModes == 1)
{
- aContext->Deactivate(myAIS);
+ Standard_Boolean isActivated = Standard_False;
+ Standard_Integer aSelectionMode = SelectionMode();
+ if (aSelectionMode == -1)
+ {
+ aContext->Deactivate(myAIS);
+ }
+ else
+ {
+ for (TColStd_ListIteratorOfListOfInteger aModeIter(anActivatedModes); aModeIter.More(); aModeIter.Next())
+ {
+ if (aModeIter.Value() == aSelectionMode)
+ {
+ isActivated = Standard_True;
+ break;
+ }
+ }
+ if (!isActivated)
+ aContext->Activate(myAIS, aSelectionMode, Standard_False);
+ }
}
else
{
- for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
+ for (Standard_Integer iSelMode = 1; iSelMode <= nbSelModes; iSelMode++)
{
- if (aModeIter.Value() == aSelectionMode)
- {
- isActivated = Standard_True;
- break;
- }
+ const Standard_Integer aSelectionMode = SelectionMode (iSelMode);
+ aContext->SetSelectionModeActive (myAIS, aSelectionMode, Standard_True/*activate*/,
+ iSelMode == 1 ? AIS_SelectionModesConcurrency_Single : AIS_SelectionModesConcurrency_GlobalOrLocal);
}
- if (!isActivated)
- aContext->Activate (myAIS, aSelectionMode, Standard_False);
}
}
}
Standard_EXPORT Standard_Boolean HasOwnMode() const;
Standard_EXPORT void UnsetMode();
-
- Standard_EXPORT Standard_Integer SelectionMode() const;
+
+ //! Returns selection mode(s) of the attribute.
+ //! It starts with 1 .. GetNbSelectionModes().
+ Standard_EXPORT Standard_Integer GetNbSelectionModes() const;
+ Standard_EXPORT Standard_Integer SelectionMode(const int index = 1) const;
//! Sets selection mode.
//! If "theTransaction" flag is OFF, modification of the attribute doesn't influence the transaction mechanism
- //! (the attribute doesn't participate in undo/redo).
+ //! (the attribute doesn't participate in undo/redo because of this modification).
//! Certainly, if any other data of the attribute is modified (display mode, color, ...),
- //! the attribute will be included into transaction.
- //! Obsolete method (may be removed later).
- Standard_EXPORT void SetSelectionMode (const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
-
+ //! the attribute will be included into undo/redo.
+ Standard_EXPORT void SetSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
+ Standard_EXPORT void AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
+
Standard_EXPORT Standard_Boolean HasOwnSelectionMode() const;
+ //! Clears all selection modes of the attribute.
Standard_EXPORT void UnsetSelectionMode();
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
--- /dev/null
+#INTERFACE CAF
+# Presentation attributes
+#
+# Testing attribute: TPrsStd_AISPresentation
+#
+# Testing command: AISSelMode
+#
+
+puts "caf003-N1"
+
+# Close/Open transaction
+NewCommand D
+
+# Set a shape
+box aBox1 100 200 300
+set aLabel 0:2
+SetShape D ${aLabel} aBox1
+
+# Initialize 3D viewer
+AISInitViewer D
+
+# Add AISPresentation attribute with parameter NS
+AISSet D ${aLabel} NS
+
+# Display presentation of NamedShape in the viewer
+AISDisplay D ${aLabel}
+
+# Close/Open transaction
+NewCommand D
+
+# Get default selection mode
+set aSelMode1 [AISSelMode D ${aLabel}]
+if { ${aSelMode1} != 0 } {
+ puts "Default selection mode is not 0"
+ return
+}
+
+# Set selection mode = 2
+AISSelMode D ${aLabel} 2
+set aSelMode2 [AISSelMode D ${aLabel}]
+if { ${aSelMode2} != 2 } {
+ puts "Selection mode is not 2"
+ return
+}
+
+# Close/Open transaction
+NewCommand D
+
+# Set selection mode = 2 4
+AISSelMode D ${aLabel} 2 4
+set aSelMode3 [AISSelMode D ${aLabel}]
+if { ${aSelMode3} != "2 4" } {
+ puts "Selection mode is not 2 4"
+ return
+}
+
+# Close/Open transaction
+NewCommand D
+
+# Undo
+Undo D
+
+set aSelMode4 [AISSelMode D ${aLabel}]
+if { ${aSelMode4} != 2 } {
+ puts "Selection mode after undo is not 2"
+ return
+}
+
+# Redo
+Redo D
+
+set aSelMode5 [AISSelMode D ${aLabel}]
+if { ${aSelMode5} != "2 4" } {
+ puts "Selection mode after redo is not 2 4"
+ return
+}
+
+puts "AISSelMode command: OK"