TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
}
-bool HYDROData_Object::IsVisible( const int theViewId ) const
-{
- ViewId2VisualStateMap aMap;
- GetViewId2VisualStateMap( aMap );
- if( aMap.find( theViewId ) != aMap.end() )
- {
- const VisualState& aVisualState = aMap[ theViewId ];
- return aVisualState.Visibility;
- }
- return false;
-}
-
-void HYDROData_Object::SetVisible( const int theViewId,
- const bool theVal )
-{
- if( theViewId == 0 )
- return;
-
- ViewId2VisualStateMap aMap;
- GetViewId2VisualStateMap( aMap );
-
- VisualState& aVisualState = aMap[ theViewId ];
- aVisualState.Visibility = theVal;
-
- SetViewId2VisualStateMap( aMap );
-}
-
bool HYDROData_Object::IsRemoved() const
{
return !myLab.HasAttribute();
return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
return NULL;
}
-
-void HYDROData_Object::GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const
-{
- theMap.clear();
-
- TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId );
- TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility );
- TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency );
- TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue );
-
- Handle(TDataStd_IntegerArray) aViewIdArray;
- Handle(TDataStd_BooleanArray) aVisibilityArray;
- Handle(TDataStd_RealArray) aTransparencyArray;
- Handle(TDataStd_RealArray) aZValueArray;
-
- if( !aViewIdLab.FindAttribute( TDataStd_IntegerArray::GetID(), aViewIdArray ) ||
- !aVisibilityLab.FindAttribute( TDataStd_BooleanArray::GetID(), aVisibilityArray ) ||
- !aTransparencyLab.FindAttribute( TDataStd_RealArray::GetID(), aTransparencyArray ) ||
- !aZValueLab.FindAttribute( TDataStd_RealArray::GetID(), aZValueArray ) )
- return;
-
- int aSize = qMin( qMin( aViewIdArray->Length(), aVisibilityArray->Length() ),
- qMin( aTransparencyArray->Length(), aZValueArray->Length() ) );
- for( int anIndex = 0; anIndex < aSize; anIndex++ )
- {
- int aViewId = aViewIdArray->Value( anIndex );
- VisualState aVisualState;
- aVisualState.Visibility = aVisibilityArray->Value( anIndex );
- aVisualState.Transparency = aTransparencyArray->Value( anIndex );
- aVisualState.ZValue = aZValueArray->Value( anIndex );
- theMap[ aViewId ] = aVisualState;
- }
-}
-
-void HYDROData_Object::SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap )
-{
- TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId );
- TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility );
- TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency );
- TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue );
-
- aViewIdLab.ForgetAllAttributes();
- aVisibilityLab.ForgetAllAttributes();
- aTransparencyLab.ForgetAllAttributes();
- aZValueLab.ForgetAllAttributes();
-
- int aSize = theMap.size();
-
- Handle(TDataStd_IntegerArray) aViewIdArray =
- TDataStd_IntegerArray::Set( aViewIdLab, 0, aSize-1 );
- Handle(TDataStd_BooleanArray) aVisibilityArray =
- TDataStd_BooleanArray::Set( aVisibilityLab, 0, aSize-1 );
- Handle(TDataStd_RealArray) aTransparencyArray =
- TDataStd_RealArray::Set( aTransparencyLab, 0, aSize-1 );
- Handle(TDataStd_RealArray) aZValueArray =
- TDataStd_RealArray::Set( aZValueLab, 0, aSize-1 );
-
- int anIndex = 0;
- ViewId2VisualStateMapIterator anIter( theMap );
- while( anIter.hasNext() )
- {
- int aViewId = anIter.next().key();
- const VisualState& aVisualState = anIter.value();
- aViewIdArray->SetValue( anIndex, aViewId );
- aVisibilityArray->SetValue( anIndex, aVisualState.Visibility );
- aTransparencyArray->SetValue( anIndex, aVisualState.Transparency );
- aZValueArray->SetValue( anIndex, aVisualState.ZValue );
- anIndex++;
- }
-}
*/
enum DataTag
{
- DataTag_First = 0, ///< first tag, to reserve
- DataTag_ViewId, ///< visual state, array of view ids
- DataTag_Visibility, ///< visual state, array of visibility states
- DataTag_Transparency, ///< visual state, array of transparency values
- DataTag_ZValue ///< visual state, array of z-values
+ DataTag_First = 0 ///< first tag, to reserve
+ // ...
};
-public:
- /**
- * Visual state data.
- */
- struct VisualState
- {
- bool Visibility;
- double Transparency;
- double ZValue;
- VisualState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
- };
- typedef QMap < int, VisualState > ViewId2VisualStateMap;
- typedef QMapIterator< int, VisualState > ViewId2VisualStateMapIterator;
-
public:
DEFINE_STANDARD_RTTI(HYDROData_Object);
*/
HYDRODATA_EXPORT void SetName(const QString& theName);
- /**
- * Returns the object visibility state for the view with specified id.
- * \param theViewId view id
- * \returns visibility state
- */
- HYDRODATA_EXPORT bool IsVisible( const int theViewId ) const;
-
- /**
- * Sets the object visibility state for the view with specified id.
- * \param theViewId view id
- * \param theVal visibility state
- */
- HYDRODATA_EXPORT void SetVisible( const int theViewId,
- const bool theVal );
-
/**
* Checks is object exists in the data structure.
* \returns true is object is not exists in the data model
*/
const char* ByteArray(const int theTag, int& theLen);
- /**
- * Returns the map containing the visual states for the specified views.
- * \param theMap map of visual states
- */
- void GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const;
-
- /**
- * Sets the map containing the visual states for the specified views.
- * \param theMap map of visual states
- */
- void SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap );
-
protected:
/// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
TDF_Label myLab; ///< label of this object
if( aPrs )
{
- bool anIsVisible = anObj->IsVisible( (size_t)aViewer );
+ bool anIsVisible = myModule->isObjectVisible( (size_t)aViewer, anObj );
aPrs->setVisible( anIsVisible );
}
}
anImage.save( aFileName );
}
- abort(); // do not commit the document command
+ commit();
}
closePreview();
if( !myIsEdit )
- anImageObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true );
+ module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
if( myIsEdit )
if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
getApp()->removeViewManager( aViewManager );
myViewManagerMap.clear();
+ myObjectStateMap.clear();
+
setMenuShown( false );
setToolShown( false );
{
anIsSelection = true;
- bool aVisibility = anObject->IsVisible( aViewId );
+ bool aVisibility = isObjectVisible( aViewId, anObject );
anIsVisibleInSelection |= aVisibility;
anIsHiddenInSelection |= !aVisibility;
// from one of the methods called below
setUpdateEnabled( false );
+ if( ( flags & UF_Viewer ) )
+ updateGV( flags & UF_GV_Init,
+ flags & UF_GV_Forced );
+
if( ( flags & UF_Model ) && getDataModel() && getApp() )
{
getDataModel()->update( getStudyId() );
// Temporary workaround to prevent breaking
- // the selection in the object browser
- qApp->processEvents();
+ // the selection in the object browser.
+ // Note: processEvents() should be called after updateGV(),
+ // otherwise the application crashes from time to time.
+ qApp->processEvents();
getApp()->updateObjectBrowser( true );
}
//if( ( flags & UF_ObjBrowser ) && getApp() )
// getApp()->updateObjectBrowser( true );
- if( ( flags & UF_Viewer ) )
- updateGV( flags & UF_GV_Init,
- flags & UF_GV_Forced );
-
if( ( flags & UF_Controls ) && getApp() )
getApp()->updateActions();
}
}
+bool HYDROGUI_Module::isObjectVisible( const int theViewId,
+ const Handle(HYDROData_Object)& theObject )
+{
+ if( theObject.IsNull() )
+ return false;
+
+ ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
+ if( anIter1 != myObjectStateMap.end() )
+ {
+ const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
+ Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
+ if( anIter2 != aName2ObjectStateMap.end() )
+ {
+ const ObjectState& anObjectState = anIter2.value();
+ return anObjectState.Visibility;
+ }
+ }
+ return false;
+}
+
+void HYDROGUI_Module::setObjectVisible( const int theViewId,
+ const Handle(HYDROData_Object)& theObject,
+ const bool theState )
+{
+ if( !theObject.IsNull() )
+ {
+ Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
+ ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
+ anObjectState.Visibility = theState;
+ }
+}
+
CAM_DataModel* HYDROGUI_Module::createDataModel()
{
return new HYDROGUI_DataModel( this );
{
if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
{
- SUIT_ViewManager* aViewManager = aViewer->getViewManager();
- ViewManagerRole aRole = getViewManagerRole( aViewManager );
- if( aRole == VMR_General )
- update( UF_Viewer );
-
- aViewer->activateTransform( GraphicsView_Viewer::FitAll );
-
if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
{
aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
//ouv: temporarily commented
//aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
}
+
+ SUIT_ViewManager* aViewManager = aViewer->getViewManager();
+ ViewManagerRole aRole = getViewManagerRole( aViewManager );
+ if( aRole != VMR_TransformImage )
+ update( UF_Viewer );
+
+ aViewer->activateTransform( GraphicsView_Viewer::FitAll );
}
}
}
#ifndef HYDROGUI_MODULE_H
#define HYDROGUI_MODULE_H
+#include <HYDROData_Object.h>
+
#include <LightApp_Module.h>
#include <QEvent>
typedef QMap < int, ViewManagerInfo > ViewManagerMap;
typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator;
+ struct ObjectState
+ {
+ bool Visibility;
+ double Transparency;
+ double ZValue;
+ ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
+ };
+ typedef QMap< QString, ObjectState > Name2ObjectStateMap;
+ typedef QMap< int, Name2ObjectStateMap > ViewId2Name2ObjectStateMap;
+
public:
HYDROGUI_Module();
virtual ~HYDROGUI_Module();
void setViewManagerRole( SUIT_ViewManager* theViewManager,
const ViewManagerRole theRole );
+ bool isObjectVisible( const int theViewId,
+ const Handle(HYDROData_Object)& theObject );
+ void setObjectVisible( const int theViewId,
+ const Handle(HYDROData_Object)& theObject,
+ const bool theState );
+
protected:
CAM_DataModel* createDataModel();
HYDROGUI_Displayer* myDisplayer;
ViewManagerMap myViewManagerMap;
+ ViewId2Name2ObjectStateMap myObjectStateMap;
bool myIsUpdateEnabled;
};
#include "HYDROGUI_Module.h"
#include "HYDROGUI_PrsImage.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Image.h>
module()->setViewManagerRole( aViewManager, HYDROGUI_Module::VMR_ObserveImage );
aViewManager->setTitle( anImageObj->GetName() );
if( GraphicsView_Viewer* aViewer = aViewManager->getViewer() )
- {
- if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
- {
- aViewPort->addItem( aPrs );
- aViewPort->fitAll();
- }
- }
+ module()->setObjectVisible( (size_t)aViewer, anImageObj, true );
}
}
- abort(); // do not commit the document command
+ module()->update( UF_Viewer );
+ commit();
}
aPolylineObj->setPolylineData(aPolylineData);
theUpdateFlags = UF_Model;
- aPolylineObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true );
+ module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true );
return true;
}
bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Object)& theObj,
HYDROGUI_Prs*& thePrs )
{
+ printf( "Update( %s )\n", qPrintable( theObj->GetName() ) );
HYDROGUI_PrsDriver::Update( theObj, thePrs );
if( theObj.IsNull() )
aPrsImage->setImage( anImage->Image() );
aPrsImage->setTransform( anImage->Trsf() );
+ QImage i = anImage->Image();
+ printf( "w = %d, h = %d\n", i.width(), i.height() );
+
aPrsImage->compute();
return true;
{
HYDROGUI_Operation::startOperation();
- startDocOperation();
-
size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
// for all objects
{
Handle(HYDROData_Object) anObject = anIterator.Current();
if( !anObject.IsNull() )
- anObject->SetVisible( aViewId, aVisibility );
+ module()->setObjectVisible( aViewId, anObject, aVisibility );
}
}
{
Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
if( !anObject.IsNull() )
- anObject->SetVisible( aViewId, aVisibility );
+ module()->setObjectVisible( aViewId, anObject, aVisibility );
}
}
- commitDocOperation();
-
module()->update( UF_Viewer );
commit();
}
if( !myIsEdit )
{
size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
- anImage1->SetVisible( aViewId, false );
- anImage2->SetVisible( aViewId, false );
- aResult->SetVisible( aViewId, true );
+ module()->setObjectVisible( aViewId, anImage1, false );
+ module()->setObjectVisible( aViewId, anImage2, false );
+ module()->setObjectVisible( aViewId, aResult, true );
+
}
theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
{
HYDROGUI_Operation::startOperation();
- startDocOperation();
+ if( !myIsLoad )
+ startDocOperation();
bool aResult = false;
if( myIsLoad )
if( aResult )
{
- commitDocOperation();
+ if( !myIsLoad )
+ commitDocOperation();
commit();
}
else
{
- abortDocOperation();
- abort(); // do not commit the document command
+ if( !myIsLoad )
+ abortDocOperation();
+ abort();
}
}
// Format: "Name|Visibility[|CoordX|CoordY]"
QString aParameters = anObject->GetName();
- int aVisibility = (int)anObject->IsVisible( aViewId );
+ int aVisibility = (int)( module()->isObjectVisible( aViewId, anObject ) );
aParameters.append( QString( "|%1" ).arg( aVisibility ) );
setVisualProperty( aPropertyMap, aViewerEntry, aParameters, true );
{
bool anIsVisible = aParameters[ aParamIndex ].toInt( &anIsOk[ ++aParamIndex ] );
if( anIsOk[ 0 ] )
- anObject->SetVisible( aViewId, anIsVisible );
+ module()->setObjectVisible( aViewId, anObject, anIsVisible );
}
}
}