diff --git a/src/DDocStd/DDocStd_DocumentCommands.cxx b/src/DDocStd/DDocStd_DocumentCommands.cxx index 6a68984e56..631469114a 100644 --- a/src/DDocStd/DDocStd_DocumentCommands.cxx +++ b/src/DDocStd/DDocStd_DocumentCommands.cxx @@ -39,6 +39,8 @@ #include #include #include +#include +#include // pour propagate #include @@ -227,6 +229,11 @@ static Standard_Integer DDocStd_Undo (Draw_Interpretor& di,Standard_Integer n, c if (!D->Redo()) di << "Redo not done\n"; } } + + // Redraw the viewer. + Handle(AIS_InteractiveContext) IC; + if (TPrsStd_AISViewer::Find(D->Main(), IC)) + IC->UpdateCurrentViewer(); return 0; } diff --git a/src/TPrsStd/TPrsStd_AISPresentation.cxx b/src/TPrsStd/TPrsStd_AISPresentation.cxx index 6eb16a2a86..c80b8491c1 100644 --- a/src/TPrsStd/TPrsStd_AISPresentation.cxx +++ b/src/TPrsStd/TPrsStd_AISPresentation.cxx @@ -65,7 +65,6 @@ Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) { aPresentation = new TPrsStd_AISPresentation(); - aPresentation->myData = aData; theLabel.AddAttribute(aPresentation); } @@ -78,19 +77,7 @@ Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set //======================================================================= Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set(const Handle(TDF_Attribute)& theMaster) { - Handle(TPrsStd_AISPresentation) aPresentation; - // create associated data (unless already there) - Handle(TDataXtd_Presentation) aData = TDataXtd_Presentation::Set (theMaster->Label(), theMaster->ID()); - if(aData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( !theMaster->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) - { - aPresentation = new TPrsStd_AISPresentation (); - aPresentation->myData = aData; - theMaster->Label().AddAttribute(aPresentation); - } - - return aPresentation; + return TPrsStd_AISPresentation::Set(theMaster->Label(), theMaster->ID()); } //======================================================================= @@ -114,7 +101,8 @@ void TPrsStd_AISPresentation::Unset (const TDF_Label& theLabel) Handle(TDataXtd_Presentation) TPrsStd_AISPresentation::getData () const { Handle(TDataXtd_Presentation) aData; - Label().FindAttribute(TDataXtd_Presentation::GetID(), aData); + if (!Label().FindAttribute(TDataXtd_Presentation::GetID(), aData)) + Standard_NoMoreObject::Raise (NO_MORE_OBJECT); return aData; } @@ -128,7 +116,6 @@ const Standard_GUID& TPrsStd_AISPresentation::GetID() return TPrsStd_AISPresentationID; } - //======================================================================= //function : Display //purpose : @@ -141,7 +128,6 @@ void TPrsStd_AISPresentation::Display(const Standard_Boolean theIsUpdate) AISDisplay(); } - //======================================================================= //function : Erase //purpose : @@ -151,7 +137,6 @@ void TPrsStd_AISPresentation::Erase(const Standard_Boolean theIsRemove) if ( IsDisplayed() ) { AISErase(theIsRemove); - //SetDisplayed (Standard_False); } } @@ -164,19 +149,15 @@ void TPrsStd_AISPresentation::Update() AISUpdate(); } - //======================================================================= //function : IsDisplayed //purpose : //======================================================================= Standard_Boolean TPrsStd_AISPresentation::IsDisplayed() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->IsDisplayed(); + return getData()->IsDisplayed(); } - //======================================================================= //function : SetDisplayed //purpose : @@ -185,45 +166,36 @@ void TPrsStd_AISPresentation::SetDisplayed(const Standard_Boolean theIsDisplayed { // this method can be called by AISUpdate() in the process of removal, // while data attribute may be already removed - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - myData->SetDisplayed(theIsDisplayed); + Backup(); + getData()->SetDisplayed(theIsDisplayed); } - //======================================================================= //function :SetDriverGUID //purpose : //======================================================================= void TPrsStd_AISPresentation::SetDriverGUID(const Standard_GUID& theGUID) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - myData->SetDriverGUID (theGUID); + Backup(); + getData()->SetDriverGUID (theGUID); } - //======================================================================= //function :GetDriverGUID //purpose : //======================================================================= Standard_GUID TPrsStd_AISPresentation::GetDriverGUID() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->GetDriverGUID(); + return getData()->GetDriverGUID(); } - //======================================================================= //function :Material //purpose : //======================================================================= Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return (Graphic3d_NameOfMaterial)myData->MaterialIndex(); + return (Graphic3d_NameOfMaterial)getData()->MaterialIndex(); } //======================================================================= @@ -232,9 +204,7 @@ Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnMaterial() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnMaterial(); + return getData()->HasOwnMaterial(); } //======================================================================= @@ -243,12 +213,10 @@ Standard_Boolean TPrsStd_AISPresentation::HasOwnMaterial() const //======================================================================= void TPrsStd_AISPresentation::UnsetMaterial() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( ! myData->HasOwnMaterial() && ! myAIS.IsNull() && !myAIS->HasMaterial() ) + if ( !getData()->HasOwnMaterial() && !myAIS.IsNull() && !myAIS->HasMaterial() ) return; - myData->UnsetMaterial(); + getData()->UnsetMaterial(); if ( myAIS.IsNull() ) AISUpdate(); @@ -270,15 +238,13 @@ void TPrsStd_AISPresentation::UnsetMaterial() //purpose : //======================================================================= void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial theName) -{ - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - - if ( myData->HasOwnMode() && myData->MaterialIndex() == theName ) +{ + Backup(); + if ( getData()->HasOwnMode() && getData()->MaterialIndex() == theName ) if ( !myAIS.IsNull() && myAIS->HasMaterial() && myAIS->Material() == theName ) return; - myData->SetMaterialIndex(theName); + getData()->SetMaterialIndex(theName); if ( myAIS.IsNull() ) AISUpdate(); @@ -303,9 +269,7 @@ void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial theName //======================================================================= Standard_Real TPrsStd_AISPresentation::Transparency() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->Transparency(); + return getData()->Transparency(); } //======================================================================= @@ -314,13 +278,12 @@ Standard_Real TPrsStd_AISPresentation::Transparency() const //======================================================================= void TPrsStd_AISPresentation::SetTransparency(const Standard_Real theValue) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if (myData->HasOwnTransparency() && myData->Transparency() == theValue) + Backup(); + if (getData()->HasOwnTransparency() && getData()->Transparency() == theValue) if ( !myAIS.IsNull() && myAIS->Transparency() == theValue ) return; - myData->SetTransparency(theValue); + getData()->SetTransparency(theValue); if ( myAIS.IsNull() ) AISUpdate(); @@ -339,19 +302,16 @@ void TPrsStd_AISPresentation::SetTransparency(const Standard_Real theValue) } } - //======================================================================= //function :UnsetTransparency //purpose : //======================================================================= void TPrsStd_AISPresentation::UnsetTransparency() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if (! myData->HasOwnTransparency()) + if (!getData()->HasOwnTransparency()) return; - myData->UnsetTransparency(); + getData()->UnsetTransparency(); if ( myAIS.IsNull() ) AISUpdate(); @@ -373,21 +333,16 @@ void TPrsStd_AISPresentation::UnsetTransparency() //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnTransparency() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnTransparency(); + return getData()->HasOwnTransparency(); } - //======================================================================= //function : Color //purpose : //======================================================================= Quantity_NameOfColor TPrsStd_AISPresentation::Color() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->Color(); + return getData()->Color(); } //======================================================================= @@ -396,9 +351,7 @@ Quantity_NameOfColor TPrsStd_AISPresentation::Color() const //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnColor() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnColor(); + return getData()->HasOwnColor(); } //======================================================================= @@ -407,11 +360,9 @@ Standard_Boolean TPrsStd_AISPresentation::HasOwnColor() const //======================================================================= void TPrsStd_AISPresentation::UnsetColor() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if (!myData->HasOwnColor() && ! myAIS.IsNull() && !myAIS->HasColor()) + if (!getData()->HasOwnColor() && ! myAIS.IsNull() && !myAIS->HasColor()) return; - myData->UnsetColor(); + getData()->UnsetColor(); if ( myAIS.IsNull() ) AISUpdate(); @@ -433,13 +384,12 @@ void TPrsStd_AISPresentation::UnsetColor() //======================================================================= void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor theColor) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( myData->HasOwnColor() && myData->Color() == theColor ) + Backup(); + if ( getData()->HasOwnColor() && getData()->Color() == theColor ) if ( !myAIS.IsNull() && myAIS->HasColor() && myAIS->Color() == theColor ) return; - myData->SetColor(theColor); + getData()->SetColor(theColor); if ( myAIS.IsNull() ) AISUpdate(); @@ -458,16 +408,13 @@ void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor theColor) } } - //======================================================================= //function :Width //purpose : //======================================================================= Standard_Real TPrsStd_AISPresentation::Width() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->Width(); + return getData()->Width(); } //======================================================================= @@ -476,9 +423,7 @@ Standard_Real TPrsStd_AISPresentation::Width() const //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnWidth() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnWidth(); + return getData()->HasOwnWidth(); } //======================================================================= @@ -487,13 +432,12 @@ Standard_Boolean TPrsStd_AISPresentation::HasOwnWidth() const //======================================================================= void TPrsStd_AISPresentation::SetWidth(const Standard_Real theWidth) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( myData->HasOwnWidth() && myData->Width() == theWidth ) + Backup(); + if ( getData()->HasOwnWidth() && getData()->Width() == theWidth ) if ( !myAIS.IsNull() && myAIS->HasWidth() && myAIS->Width() == theWidth ) return; - myData->SetWidth(theWidth); + getData()->SetWidth(theWidth); if( !myAIS.IsNull() ) { @@ -515,13 +459,11 @@ void TPrsStd_AISPresentation::SetWidth(const Standard_Real theWidth) //======================================================================= void TPrsStd_AISPresentation::UnsetWidth() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( !myData->HasOwnWidth() ) + if ( !getData()->HasOwnWidth() ) if ( !myAIS.IsNull() && !myAIS->HasWidth() ) return; - myData->UnsetWidth(); + getData()->UnsetWidth(); if( myAIS.IsNull() ) AISUpdate(); @@ -537,17 +479,13 @@ void TPrsStd_AISPresentation::UnsetWidth() } } - //======================================================================= //function : Mode //purpose : //======================================================================= - Standard_Integer TPrsStd_AISPresentation::Mode() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->Mode(); + return getData()->Mode(); } //======================================================================= @@ -556,25 +494,21 @@ Standard_Integer TPrsStd_AISPresentation::Mode() const //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnMode() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnMode(); + return getData()->HasOwnMode(); } - //======================================================================= //function : SetMode //purpose : //======================================================================= void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( myData->HasOwnMode() && myData->Mode() == theMode ) + Backup(); + if ( getData()->HasOwnMode() && getData()->Mode() == theMode ) if ( !myAIS.IsNull() && myAIS->DisplayMode() == theMode ) return; - myData->SetMode(theMode); + getData()->SetMode(theMode); if ( myAIS.IsNull() ) AISUpdate(); @@ -593,20 +527,17 @@ void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode) } } - //======================================================================= //function : UnsetMode //purpose : //======================================================================= void TPrsStd_AISPresentation::UnsetMode() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - if ( !myData->HasOwnMode() ) + if ( !getData()->HasOwnMode() ) if ( !myAIS.IsNull() && !myAIS->HasDisplayMode() ) return; - myData->UnsetMode(); + getData()->UnsetMode(); if ( myAIS.IsNull() ) AISUpdate(); @@ -626,12 +557,9 @@ void TPrsStd_AISPresentation::UnsetMode() //function : SelectionMode //purpose : //======================================================================= - Standard_Integer TPrsStd_AISPresentation::SelectionMode() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->SelectionMode(); + return getData()->SelectionMode(); } //======================================================================= @@ -640,9 +568,7 @@ Standard_Integer TPrsStd_AISPresentation::SelectionMode() const //======================================================================= Standard_Boolean TPrsStd_AISPresentation::HasOwnSelectionMode() const { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - return myData->HasOwnSelectionMode(); + return getData()->HasOwnSelectionMode(); } //======================================================================= @@ -651,10 +577,8 @@ Standard_Boolean TPrsStd_AISPresentation::HasOwnSelectionMode() const //======================================================================= void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelectionMode) { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - myData->SetSelectionMode (theSelectionMode); - + Backup(); + getData()->SetSelectionMode (theSelectionMode); AISUpdate(); } @@ -664,10 +588,7 @@ void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelecti //======================================================================= void TPrsStd_AISPresentation::UnsetSelectionMode() { - if(myData.IsNull()) - Standard_NoMoreObject::Raise (NO_MORE_OBJECT); - myData->UnsetSelectionMode (); - + getData()->UnsetSelectionMode (); AISUpdate(); } @@ -708,7 +629,6 @@ void TPrsStd_AISPresentation::Restore(const Handle(TDF_Attribute)& /*theWith*/) myAIS.Nullify(); } - //======================================================================= //function : Paste //purpose : @@ -721,10 +641,8 @@ void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& theInto, anInto->Backup(); anInto->myAIS.Nullify(); - anInto->myData.Nullify(); } - //======================================================================= //function : AfterAddition //purpose : erase if displayed @@ -753,18 +671,15 @@ void TPrsStd_AISPresentation::BeforeForget() { // Remove AISObject from context. AISErase(Standard_True); myAIS.Nullify(); - myData.Nullify(); } } - //======================================================================= //function : AfterResume //purpose : display if displayed //======================================================================= void TPrsStd_AISPresentation::AfterResume() { - myData = getData(); AISUpdate(); if ( IsDisplayed() ) AISDisplay(); @@ -776,9 +691,8 @@ void TPrsStd_AISPresentation::AfterResume() //function : BeforeUndo //purpose : le NamedShape associe doit etre present //======================================================================= - Standard_Boolean TPrsStd_AISPresentation::BeforeUndo (const Handle(TDF_AttributeDelta)& AD, - const Standard_Boolean ) + const Standard_Boolean ) { Handle(TPrsStd_AISPresentation) P; AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P); @@ -799,12 +713,10 @@ Standard_Boolean TPrsStd_AISPresentation::BeforeUndo (const Handle(TDF_Attribute return Standard_True; } - //======================================================================= //function : AfterUndo //purpose : le NamedShape associe doit etre present //======================================================================= - Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeDelta)& AD, const Standard_Boolean ) { @@ -827,7 +739,6 @@ Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeD return Standard_True; } - //======================================================================= //function : AISUpdate //purpose : @@ -835,7 +746,7 @@ Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeD void TPrsStd_AISPresentation::AISUpdate() { Backup(); - myData->Backup(); + getData()->Backup(); Handle(AIS_InteractiveContext) aContext; if ( !Label().IsNull() ) { @@ -851,7 +762,6 @@ void TPrsStd_AISPresentation::AISUpdate() if ( aDriver->Update(Label(), aNewObj) ) { myAIS = aNewObj; - myData = getData(); aNewObj->SetOwner(this); } } @@ -866,7 +776,6 @@ void TPrsStd_AISPresentation::AISUpdate() // Driver has built new AIS. myAIS = anObj; - myData = getData(); anObj->SetOwner(this); } } @@ -936,24 +845,29 @@ void TPrsStd_AISPresentation::AISUpdate() aContext->Redisplay(myAIS, Standard_False); if (HasOwnSelectionMode()) { - //aContext = aContext.IsNull() ? myAIS->GetContext() : aContext; if (!aContext.IsNull()) { TColStd_ListOfInteger anActivatedModes; aContext->ActivatedModes (myAIS, anActivatedModes); Standard_Boolean isActivated = Standard_False; Standard_Integer aSelectionMode = SelectionMode(); - for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next()) + if (aSelectionMode == -1) { - if (aModeIter.Value() == aSelectionMode) - { - isActivated = Standard_True; - break; - } + 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); } - - if (!isActivated) - aContext->Activate (myAIS, aSelectionMode, Standard_False); } } @@ -992,7 +906,6 @@ void TPrsStd_AISPresentation::AISDisplay() } } - //======================================================================= //function : AISErase //purpose : @@ -1004,10 +917,11 @@ void TPrsStd_AISPresentation::AISErase(const Standard_Boolean theIsRemove) if ( !myAIS.IsNull() ) { Backup(); - myData->Backup(); - SetDisplayed(Standard_False); if ( !Label().IsNull() ) { + if (IsAttribute(TDataXtd_Presentation::GetID())) + SetDisplayed(Standard_False); + Handle(TPrsStd_AISViewer) viewer; if( !TPrsStd_AISViewer::Find(Label(), viewer) ) return; @@ -1048,7 +962,6 @@ void TPrsStd_AISPresentation::AISErase(const Standard_Boolean theIsRemove) } } - //======================================================================= //function :GetAIS //purpose : @@ -1058,7 +971,6 @@ Handle(AIS_InteractiveObject) TPrsStd_AISPresentation::GetAIS() const return myAIS; } - //======================================================================= //function : getAISContext //purpose : diff --git a/src/TPrsStd/TPrsStd_AISPresentation.hxx b/src/TPrsStd/TPrsStd_AISPresentation.hxx index 316caa0ce9..672ff5f9b4 100644 --- a/src/TPrsStd/TPrsStd_AISPresentation.hxx +++ b/src/TPrsStd/TPrsStd_AISPresentation.hxx @@ -189,10 +189,12 @@ public: DEFINE_STANDARD_RTTIEXT(TPrsStd_AISPresentation,TDF_Attribute) -private: +protected: //! Returns attribute storing presentation data - Handle(TDataXtd_Presentation) getData () const; + Standard_EXPORT virtual Handle(TDataXtd_Presentation) getData () const; + +private: Handle(AIS_InteractiveContext) getAISContext() const; @@ -210,7 +212,6 @@ private: private: Handle(AIS_InteractiveObject) myAIS; - Handle(TDataXtd_Presentation) myData; }; #endif // _TPrsStd_AISPresentation_HeaderFile