std::string PARAMETER_IS_2D( const int i ) {\r
return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Is2D", i );\r
}\r
- std::string PARAMETER_NAME( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Name", i );\r
- }\r
std::string PARAMETER_TEXT( const int i ) {\r
return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Text", i );\r
}\r
std::string PARAMETER_SHAPE( const int i ) {\r
return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Shape", i );\r
}\r
-}\r
+\r
+ // REGEXP pattern for converting array of entries into plain text string.\r
+ // The pattern has the following structure:\r
+ // ENTRY: { text[string] : visibility[bool] : screen fixed[bool] : position[xyz] : attach[xyz] }\r
+ static const QString PATTERN_ITEM_GROUP = "\\{ (Text=(?::{2,}|.)*:(?!:)Screen=.*:Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=.*:ShapeType=.*) \\}";\r
+ static const QString PATTERN_ITEM = "Text=((?::{2,}|.)*):(?!:)Screen=(\\d{1}):Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=(\\-?\\d{1,}):ShapeType=(\\d{1})";\r
+ static QString toPattern (const QString& theText,\r
+ const bool theIsFixed,\r
+ const gp_Pnt& thePosition,\r
+ const gp_Pnt& theAttach,\r
+ const int theShapeIndex,\r
+ const int theShapeType)\r
+ {\r
+ return QString( "{ Text=" ) + theText +\r
+ QString( ":" ) + QString( "Screen=" ) + QString::number( theIsFixed ? 1 : 0 ) +\r
+ QString( ":" ) + QString( "Position={" ) +\r
+ QString::number( thePosition.X() ) + QString( ":" ) + \r
+ QString::number( thePosition.Y() ) + QString( ":" ) + \r
+ QString::number( thePosition.Z() ) + QString( "}" ) + \r
+ QString( ":" ) + QString( "Attach={" ) +\r
+ QString::number( theAttach.X() ) + QString( ":" ) + \r
+ QString::number( theAttach.Y() ) + QString( ":" ) + \r
+ QString::number( theAttach.Z() ) + QString( "}" ) +\r
+ QString( ":" ) + QString( "ShapeIdx=" ) + QString::number( theShapeIndex ) +\r
+ QString( ":" ) + QString( "ShapeType=" ) + QString::number( theShapeType ) +\r
+ QString( " }" );\r
+ }\r
+};\r
\r
//=================================================================================\r
// function : FindAttributes\r
{\r
aParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN );\r
aParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN );\r
- aParameterMap->RemoveID( PARAMETER_NAME( anI ), PT_STRING );\r
aParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING );\r
aParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY );\r
aParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY );\r
aParameterMap->RemoveID( PARAMETER_COUNT, PT_INTEGER );\r
}\r
\r
+//=================================================================================\r
+// function : ExportAsPropertyString\r
+// purpose : \r
+//=================================================================================\r
+QString GEOMGUI_AnnotationAttrs::ExportAsPropertyString() const\r
+{\r
+ QStringList anItems;\r
+\r
+ for ( int anI = 0; anI < GetNbAnnotation(); ++anI )\r
+ {\r
+ Properties aEntry;\r
+\r
+ GetProperties( anI, aEntry );\r
+\r
+ anItems.append( toPattern( aEntry.Text,\r
+ aEntry.IsScreenFixed,\r
+ aEntry.Position,\r
+ aEntry.Attach,\r
+ aEntry.ShapeIndex,\r
+ aEntry.ShapeType ) );\r
+ }\r
+\r
+ return anItems.join( ":" );\r
+}\r
+\r
+//=================================================================================\r
+// function : ImportFromPropertyString\r
+// purpose : \r
+//=================================================================================\r
+void GEOMGUI_AnnotationAttrs::ImportFromPropertyString( const QString& theString )\r
+{\r
+ SetNbAnnotation( 0 );\r
+\r
+ QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP );\r
+ QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" );\r
+ aRegExpItemGroups.setMinimal( true );\r
+ aRegExpItem.setMinimal( true );\r
+\r
+ int aPos = 0;\r
+ while ( ( aPos = aRegExpItemGroups.indexIn( theString, aPos ) ) != -1 )\r
+ {\r
+ aPos += aRegExpItemGroups.matchedLength();\r
+\r
+ QString aStrItem = aRegExpItemGroups.cap(1);\r
+\r
+ if ( aRegExpItem.indexIn( aStrItem ) < 0 )\r
+ {\r
+ continue;\r
+ }\r
+\r
+ QString aStrText = aRegExpItem.cap( 1 );\r
+ QString aStrFixed = aRegExpItem.cap( 2 );\r
+ QString aStrPosX = aRegExpItem.cap( 3 );\r
+ QString aStrPosY = aRegExpItem.cap( 4 );\r
+ QString aStrPosZ = aRegExpItem.cap( 5 );\r
+ QString aStrAttX = aRegExpItem.cap( 6 );\r
+ QString aStrAttY = aRegExpItem.cap( 7 );\r
+ QString aStrAttZ = aRegExpItem.cap( 8 );\r
+ QString aStrShapeIdx = aRegExpItem.cap( 9 );\r
+ QString aStrShapeType = aRegExpItem.cap( 10 );\r
+ aStrText.replace( "::", ":" );\r
+\r
+ Properties aEntry;\r
+ aEntry.Text = aStrText;\r
+ aEntry.IsVisible = false;\r
+ aEntry.IsScreenFixed = aStrFixed.toInt() != 0;\r
+ aEntry.Position.SetX( aStrPosX.toDouble() );\r
+ aEntry.Position.SetY( aStrPosY.toDouble() );\r
+ aEntry.Position.SetZ( aStrPosZ.toDouble() );\r
+ aEntry.Attach.SetX( aStrAttX.toDouble() );\r
+ aEntry.Attach.SetY( aStrAttY.toDouble() );\r
+ aEntry.Attach.SetZ( aStrAttZ.toDouble() );\r
+ aEntry.ShapeIndex = aStrShapeIdx.toInt();\r
+ aEntry.ShapeType = aStrShapeType.toInt();\r
+\r
+ Append( aEntry );\r
+ }\r
+}\r
+\r
//=================================================================================\r
// function : SetNbAnnotation\r
// purpose : \r
{\r
myParameterMap->SetBool( PARAMETER_IS_VISIBLE( anI ), true );\r
myParameterMap->SetBool( PARAMETER_IS_2D( anI ), false );\r
- myParameterMap->SetString( PARAMETER_NAME( anI ), std::string() );\r
myParameterMap->SetString( PARAMETER_TEXT( anI ), std::string() );\r
myParameterMap->SetRealArray( PARAMETER_POSITION( anI ), std::vector<double>(3, 0.0) );\r
myParameterMap->SetRealArray( PARAMETER_ATTACH( anI ), std::vector<double>(3, 0.0) );\r
{\r
myParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN );\r
myParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN );\r
- myParameterMap->RemoveID( PARAMETER_NAME( anI ), PT_STRING );\r
myParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING );\r
myParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY );\r
myParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY );\r
return myParameterMap->GetInt( PARAMETER_COUNT );\r
}\r
\r
-//=================================================================================\r
-// function : SetName\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetName( const int theIndex, const QString& theName )\r
-{\r
- myParameterMap->SetString( PARAMETER_NAME( theIndex ), theName.toStdString() );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetName\r
-// purpose : \r
-//=================================================================================\r
-QString GEOMGUI_AnnotationAttrs::GetName( const int theIndex ) const\r
-{\r
- return QString::fromStdString( myParameterMap->GetString( PARAMETER_NAME( theIndex ) ) );\r
-}\r
-\r
//=================================================================================\r
// function : SetVisible\r
// purpose : \r
gp_Trsf aToShapeLCS;\r
aToShapeLCS.SetTransformation( gp_Ax3(), theShapeLCS );\r
\r
- this->SetName( theIndex, theProps.Name );\r
this->SetText( theIndex, theProps.Text );\r
this->SetIsVisible( theIndex, theProps.IsVisible );\r
this->SetIsScreenFixed( theIndex, theProps.IsScreenFixed );\r
//=================================================================================\r
void GEOMGUI_AnnotationAttrs::GetProperties( const int theIndex, Properties& theProps ) const\r
{\r
- theProps.Name = this->GetName( theIndex );\r
theProps.Text = this->GetText( theIndex );\r
theProps.IsVisible = this->GetIsVisible( theIndex );\r
theProps.IsScreenFixed = this->GetIsScreenFixed( theIndex );\r
//! Remove annotation data fields for an object.
GEOMGUI_EXPORT static void Remove( const _PTR(SObject)& theObject );
+// Import / Export
+public:
+
+ //! Exports annotation records as a property string.
+ GEOMGUI_EXPORT QString ExportAsPropertyString() const;
+
+ //! Imports annotation records from a property string.
+ GEOMGUI_EXPORT void ImportFromPropertyString( const QString& theString );
+
public:
/*!
*/
struct Properties
{
- QString Name; //!< Application name of annotation.
QString Text; //!< Displayed annotation text.
bool IsVisible; //!< Application visibility flag of annotation.
bool IsScreenFixed; //!< Fixed screen mode flag.
//! Returns number of annotation definitions stored on the object.
GEOMGUI_EXPORT int GetNbAnnotation() const;
- //! Sets application name property of an annotation definition.
- //! @param theIndex [in] the index of the annotation definition.
- //! @param theName [in] the new application name.
- GEOMGUI_EXPORT void SetName( const int theIndex, const QString& theName );
-
- //! Returns application name of an annotation definition.
- //! @param theIndex [in] the index of the annotation definition.
- GEOMGUI_EXPORT QString GetName( const int theIndex ) const;
-
//! Sets application visibility state of an annotation definition.
//! @param theIndex [in] the index of the annotation definition.
//! @param theIsVisible [in] the visibility state.
private:
- GEOMGUI_AnnotationAttrs( const _PTR(SObject)& theObject,
- const _PTR(AttributeParameter)& theParameter )
+ GEOMGUI_AnnotationAttrs( const _PTR(SObject)& theObject, const _PTR(AttributeParameter)& theParameter )
: myObj( theObject ),
myParameterMap( theParameter ) {}
aPresentation->SetOwner( anIO );
}
- aPresentation->SetOwner( new SALOME_InteractiveObject( getEntry( theObject ).c_str(), "GEOM", getName( theObject ).c_str() ) );
+ //aPresentation->SetOwner( new SALOME_InteractiveObject( getEntry( theObject ).c_str(), "GEOM", getName( theObject ).c_str() ) );
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) );
myVisualized[aView] = anEntryToMap;
// change persistent for the entry: set visible state in true for indices which presentations are shown
- storeVisibleState( theEntry, theView );
+ storeVisibleState( theEntry, theView, theIndex );
}
void GEOMGUI_AnnotationMgr::Erase( const QString& theEntry, const int theIndex, SALOME_View* theView )
if ( !anAnnotationToPrs.contains( theIndex ) )
return;
-
// erase presentation from the viewer
SALOME_Prs* aPrs = anAnnotationToPrs[theIndex];
aView->Erase( getDisplayer(), aPrs );
myVisualized[aView] = anEntryToAnnotation;
// change persistent for the entry: set visible state in true for indices which presentations are shown
- storeVisibleState( theEntry, theView );
+ storeVisibleState( theEntry, theView, theIndex );
}
void GEOMGUI_AnnotationMgr::DisplayVisibleAnnotations( const QString& theEntry, SALOME_View* theView )
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
_PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
+ if ( !aSObj )
+ {
+ return aDisplayedIndices;
+ }
const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
if ( !aShapeAnnotations.IsNull() )
{
}
}
-void GEOMGUI_AnnotationMgr::storeVisibleState( const QString& theEntry, SALOME_View* theView )
+void GEOMGUI_AnnotationMgr::storeVisibleState( const QString& theEntry, SALOME_View* theView, const int theIndex )
{
SALOME_View* aView = viewOrActiveView( theView );
if ( !aView || !myVisualized.contains( aView ) )
_PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
if ( !aShapeAnnotations.IsNull() ) {
- const int aCount = aShapeAnnotations->GetNbAnnotation();
- for ( int anIndex = 0; anIndex < aCount; ++anIndex )
- {
- bool aVisible = anAnnotationToPrs.contains( anIndex );
- aShapeAnnotations->SetIsVisible( anIndex, aVisible );
- }
+
+ bool aVisible = anAnnotationToPrs.contains( theIndex );
+ aShapeAnnotations->SetIsVisible( theIndex, aVisible );
}
}
GEOM::GEOM_Object_ptr& anObject,
GEOMGUI_AnnotationAttrs::Properties& aProperty );
- void storeVisibleState( const QString& theEntry, SALOME_View* theView );
+ void storeVisibleState( const QString& theEntry, SALOME_View* theView, const int theIndex );
std::string getEntry( const GEOM::GEOM_Object_ptr theObject );
return !myAttr.IsNull() ? myAttr->GetText( theIndex ) : QString();
}
virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
- return annotationMgr()->IsDisplayed(myEntry, theIndex);
+ GEOMGUI_AnnotationMgr* aMgr = annotationMgr();
+ if (!aMgr) {
+ return false;
+ }
+ return aMgr->IsDisplayed( myEntry, theIndex );
+ //return annotationMgr()->IsDisplayed(myEntry, theIndex);
//return !myAttr.IsNull() ? myAttr->GetIsVisible( theIndex ) : false;
}
virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
+ GEOMGUI_AnnotationMgr* aMgr = annotationMgr();
+ if (!aMgr) {
+ return;
+ }
if (theIsVisible)
annotationMgr()->Display(myEntry, theIndex);
else
{
CAM_Application* anApp = dynamic_cast<CAM_Application*>(myStudy->application());
GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
+ if (!aModule) {
+ return NULL;
+ }
return aModule->GetAnnotationMgr();
}
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
if ( !appStudy || !appStudy->studyDS() )
return;
+
_PTR(Study) studyDS = appStudy->studyDS();
// componentName is used for encoding of entries when storing them in IParameters
QList<SUIT_ViewManager*> lst;
QList<SUIT_ViewManager*>::Iterator it;
+ GEOMGUI_AnnotationMgr* aAnnotationMgr = GetAnnotationMgr();
+
// main cycle to store parameters of displayed objects
lst.clear();
getApp()->viewManagers(lst);
ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
}
- std::string anAnnotationInfo = GetAnnotationMgr()->getDisplayedIndicesInfo(entry.c_str(), aView).toStdString();
- if (!anAnnotationInfo.empty()) {
- param = occParam + "AttributeParameter";
- ip->setParameter(entry, param.toStdString(), anAnnotationInfo);
+ if ( aAnnotationMgr ) {
+ std::string anAnnotationInfo = GetAnnotationMgr()->getDisplayedIndicesInfo( o_it.key().toLatin1().data(), aView ).toStdString();
+ if (!anAnnotationInfo.empty()) {
+ param = occParam + "ShapeAnnotationVisibleItems";
+ ip->setParameter(entry, param.toStdString(), anAnnotationInfo);
+ }
}
-
} // object iterator
} // for (views)
} // for (viewManagers)
- // store dimension attributes of objects:
+ // store shape annotation and dimension attributes of objects:
// since the displayed object always persists in property map, we remember the object entries
// on the passes when we store viewer related properties - to avoid extra iterations on GEOM component tree.
- QString aDimensionParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::Dimensions );
+ const QString aDimensionParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::Dimensions );
+ const QString aAnnotationParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::ShapeAnnotations );
QSet<QString>::ConstIterator aEntryIt = anEntriesToStoreShared.constBegin();
for ( ; aEntryIt != anEntriesToStoreShared.constEnd(); ++aEntryIt )
{
std::string aStudyEntry = (*aEntryIt).toLatin1().data();
- std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName);
+ std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName );
// store dimension parameters
GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry );
-
- if ( aDimensions.GetNumber() == 0 )
- {
- continue;
+ if ( aDimensions.GetNumber() != 0 ) {
+ ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
}
- ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
-
- // store annotation parameters
- //GetAnnotationMgr()->storeVisualParameters(ip, aStudyEntry);
- //_PTR(IParameters) ip = ClientFactory::getIParameters(ap);
+ _PTR(SObject) aObj( studyDS->FindObjectID( aStudyEntry ) );
+ const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aObj );
+ if ( !aShapeAnnAttr.IsNull() ) {
+ ip->setParameter( aStoreEntry, aAnnotationParam.toStdString(), aShapeAnnAttr->ExportAsPropertyString().toLatin1().data() );
+ }
}
}
GEOMGUI_DimensionProperty aDimensionProp( aValuesStr );
aDimensionProp.SaveToAttribute( appStudy, entry.toLatin1().data() );
}
+ else if ( aParamNameStr == GEOM::propertyName( GEOM::ShapeAnnotations ) )
+ {
+ Handle(GEOMGUI_AnnotationAttrs) anAttr =
+ GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( so, appStudy );
+
+ anAttr->ImportFromPropertyString( aValuesStr );
+ }
continue;
}
aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
} else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
- } else if (paramNameStr == "AttributeParameter") {
- aListOfMap[viewIndex].insert( "AttributeParameter", val);
+ } else if (paramNameStr == "ShapeAnnotationVisibleItems") {
+ aListOfMap[viewIndex].insert( "ShapeAnnotationVisibleItems", val);
}
} // for names/parameters iterator
SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
displayer()->Display(entry, true, aView);
- PropMap aProps = aListOfMap[index];
- if ( aProps.contains( "AttributeParameter" ) )
- GetAnnotationMgr()->setDisplayedIndicesInfo( entry, aView, aProps["AttributeParameter"].toString() );
+ PropMap& aProps = aListOfMap[index];
+ if ( aProps.contains( "ShapeAnnotationVisibleItems" ) )
+ GetAnnotationMgr()->setDisplayedIndicesInfo( entry, aView, aProps["ShapeAnnotationVisibleItems"].toString() );
}
}
} // for entries iterator
occVMod->Repaint();
}
}
+
+ if ( myTextTreeWdg ) {
+ myTextTreeWdg->updateTree();
+ }
}
// Compute current name mode of the viewer
// default presentation values
myIsPositionDefined = false;
- myAnnotationProperties.Name = getNewObjectName();
myAnnotationProperties.Text = tr( "ANNOTATION_PREFIX" );
myAnnotationProperties.IsVisible = false;
myAnnotationProperties.IsScreenFixed = false;
Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations =
GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( aSObj, aStudy );
- myAnnotationProperties.Name = getNewObjectName(); // update here as we do not listen name modification
myAnnotationProperties.IsVisible = true; // initially created annotation is hidden
aShapeAnnotations->Append( myAnnotationProperties );