Salome HOME
updated copyright message
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_MarkerDlg.cxx
index cd85f26b53fba868016ad87886aa42a563697df7..4ff6bcec0be9eeae7e24f39fc3f927819bc3527d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -26,8 +26,6 @@
 #include <GEOM_Constants.h>
 #include <GEOM_Displayer.h>
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <QtxComboBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
@@ -38,7 +36,6 @@
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 #include <QButtonGroup>
 #include <QGridLayout>
@@ -171,13 +168,9 @@ void GEOMToolsGUI_MarkerDlg::setStandardMarker( GEOM::marker_type type, GEOM::ma
   if ( type > GEOM::MT_NONE && type < GEOM::MT_USER ) {
     myTypeGroup->button( 0 )->setChecked( true );
     myWGStack->setCurrentIndex( 0 );
-    myStdTypeCombo->setCurrentIndex( (int)type - 1 );
-#ifdef WIN32
-    int asize = max( (int)GEOM::MS_10, min( (int)GEOM::MS_70, (int)size ) );
-#else
+    myStdTypeCombo->setCurrentId( (int)type );
     int asize = std::max( (int)GEOM::MS_10, std::min( (int)GEOM::MS_70, (int)size ) );
-#endif
-    myStdScaleCombo->setCurrentIndex( asize-1 );
+    myStdScaleCombo->setCurrentId( asize );
   }
 }
 
@@ -193,17 +186,17 @@ void GEOMToolsGUI_MarkerDlg::setCustomMarker( int id )
 
 GEOM::marker_type GEOMToolsGUI_MarkerDlg::getMarkerType() const
 {
-  return myWGStack->currentIndex() == 0 ? (GEOM::marker_type)myStdTypeCombo->currentId() : GEOM::MT_USER;
+  return myWGStack->currentIndex() == 0 ? (GEOM::marker_type)myStdTypeCombo->currentId().toInt() : GEOM::MT_USER;
 }
 
 GEOM::marker_size GEOMToolsGUI_MarkerDlg::getStandardMarkerScale() const
 {
-  return myWGStack->currentIndex() == 0 ? (GEOM::marker_size)myStdScaleCombo->currentId() : GEOM::MS_NONE;
+  return myWGStack->currentIndex() == 0 ? (GEOM::marker_size)myStdScaleCombo->currentId().toInt() : GEOM::MS_NONE;
 }
 
 int GEOMToolsGUI_MarkerDlg::getCustomMarkerID() const
 {
-  return myWGStack->currentIndex() == 1 ? myCustomTypeCombo->currentId() : 0;
+  return myWGStack->currentIndex() == 1 ? myCustomTypeCombo->currentId().toInt() : 0;
 }
 
 void GEOMToolsGUI_MarkerDlg::accept()
@@ -223,22 +216,24 @@ void GEOMToolsGUI_MarkerDlg::accept()
             _PTR(SObject) aSObject( study->FindObjectID( it.Value()->getEntry() ) );
             GEOM::GEOM_Object_var anObject =
               GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( aSObject ) );
-            if ( !anObject->_is_nil() ) {
-              if ( myWGStack->currentIndex() == 0 ) {
+            if ( myWGStack->currentIndex() == 0 ) {
+              if ( !anObject->_is_nil() && GeometryGUI::IsInGeomComponent( aSObject )) {
                 anObject->SetMarkerStd( getMarkerType(), getStandardMarkerScale() );
-                QString aMarker = "%1%2%3";
-                aMarker = aMarker.arg(getMarkerType());
-                aMarker = aMarker.arg(GEOM::subSectionSeparator());
-                aMarker = aMarker.arg(getStandardMarkerScale());
-                getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),GEOM::propertyName( GEOM::PointMarker ), aMarker);
               }
-              else if ( getCustomMarkerID() > 0 ) {
+              QString aMarker = "%1%2%3";
+              aMarker = aMarker.arg(getMarkerType());
+              aMarker = aMarker.arg(GEOM::subSectionSeparator());
+              aMarker = aMarker.arg(getStandardMarkerScale());
+              getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),GEOM::propertyName( GEOM::PointMarker ), aMarker);
+            }
+            else if ( getCustomMarkerID() > 0 ) {
+              if ( !anObject->_is_nil() && GeometryGUI::IsInGeomComponent( aSObject )) {
                 anObject->SetMarkerTexture( getCustomMarkerID() );
-                getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),GEOM::propertyName( GEOM::PointMarker ), QString::number(getCustomMarkerID()));
               }
+              getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),GEOM::propertyName( GEOM::PointMarker ), QString::number(getCustomMarkerID()));
             }
           }
-          GEOM_Displayer displayer( getStudy() );
+          GEOM_Displayer displayer;
           displayer.Redisplay( selected, true );
           selMgr->setSelectedObjects( selected );
         }
@@ -278,9 +273,9 @@ void GEOMToolsGUI_MarkerDlg::init()
   // ---
   
   GEOM::GEOM_Gen_var engine = GeometryGUI::GetGeomGen();
-  myOperation = engine->GetIInsertOperations( getStudy()->id() );
+  myOperation = engine->GetIInsertOperations();
   GEOM::ListOfLong_var ids = myOperation->GetAllTextures();
-  for ( int i = 0; i < ids->length(); i++ )
+  for ( int i = 0; i < (int)ids->length(); i++ )
     addTexture( ids[i] );
 
   // ---
@@ -299,8 +294,9 @@ void GEOMToolsGUI_MarkerDlg::init()
           _PTR(SObject) aSObject( study->FindObjectID( it.Value()->getEntry() ) );
           GEOM::GEOM_Object_var anObject =
             GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( aSObject ) );
-          if ( !anObject->_is_nil() ) {
+          if ( !anObject->_is_nil() && GeometryGUI::IsInGeomComponent( aSObject )) {
             GEOM::marker_type mtype = anObject->GetMarkerType();
+
             if ( aType == -1 )
               aType = mtype;
             else if ( aType != mtype ) {
@@ -322,6 +318,47 @@ void GEOMToolsGUI_MarkerDlg::init()
                 break;
             }
           }
+          else {
+            // try study object properties
+            QStringList aMarkerProp;
+            SUIT_ViewWindow* window = getStudy()->application()->desktop()->activeWindow();
+            if (window && window->getViewManager()) {
+              int mgrId = window->getViewManager()->getGlobalId();
+              PropMap aPropMap = getStudy()->getObjectProperties(mgrId, it.Value()->getEntry());
+              aMarkerProp = aPropMap.value(GEOM::propertyName(GEOM::PointMarker)).toString().split( GEOM::subSectionSeparator());
+            }
+            if ( aMarkerProp.size() == 2 ) {
+              // standard marker string contains "TypeOfMarker:ScaleOfMarker"
+              GEOM::marker_type mtype = (GEOM::marker_type)aMarkerProp[0].toInt();
+              GEOM::marker_size msize = (GEOM::marker_size)aMarkerProp[1].toInt();
+
+              if ( aType == -1 )
+                aType = mtype;
+              else if ( aType != mtype ) {
+                aType = (GEOM::marker_type)-1;
+                break;
+              }
+              if ( aSize == -1 )
+                aSize = msize;
+              else if ( aSize != msize )
+                break;
+            }
+            else if ( aMarkerProp.size() == 1 ) {
+              // custom marker string contains "IdOfTexture"
+              int mtexture = aMarkerProp[0].toInt();
+
+              if ( aType == -1 )
+                aType = GEOM::MT_USER;
+              else if ( aType !=  GEOM::MT_USER) {
+                aType = (GEOM::marker_type)-1;
+                break;
+              }
+              if ( aTexture == 0 )
+                aTexture = mtexture;
+              else if ( aTexture != mtexture )
+                break;
+            }
+          }
         }
       }
     }
@@ -340,7 +377,7 @@ void GEOMToolsGUI_MarkerDlg::addTexture( int id, bool select ) const
   if ( id > 0 && myCustomTypeCombo->index( id ) == -1 ) {
     int tWidth, tHeight;
 
-    Handle(TColStd_HArray1OfByte) texture = GeometryGUI::getTexture(getStudy(), id, tWidth, tHeight);
+    Handle(TColStd_HArray1OfByte) texture = GeometryGUI::getTexture(id, tWidth, tHeight);
 
     if ( !texture.IsNull() && texture->Length() == tWidth*tHeight/8 ) {
       QImage image( tWidth, tHeight, QImage::Format_Mono );
@@ -376,7 +413,7 @@ void GEOMToolsGUI_MarkerDlg::browse()
   filters << tr( "Texture files (*.dat)" ) << tr( "All files (*)" );
   QString aFileName = SUIT_Session::session()->activeApplication()->getFileName( true, QString(), filters.join( ";;" ), tr( "LOAD_TEXTURE_TLT" ), this );
   if ( !aFileName.isEmpty() ) {
-    addTexture( myOperation->LoadTexture( aFileName.toLatin1().constData() ), true );
+    addTexture( myOperation->LoadTexture( aFileName.toUtf8().constData() ), true );
   }
 }