]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Issue 0020012: EDF 831 GEOM : API for points representation in 3D viewer
authorvsr <vsr@opencascade.com>
Tue, 3 Nov 2009 10:48:50 +0000 (10:48 +0000)
committervsr <vsr@opencascade.com>
Tue, 3 Nov 2009 10:48:50 +0000 (10:48 +0000)
15 files changed:
src/GEOM/GEOM_Engine.cxx
src/GEOM/GEOM_Engine.hxx
src/GEOM/GEOM_Object.cxx
src/GEOM/GEOM_Object.hxx
src/GEOMGUI/GEOM_Displayer.cxx
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI.h
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
src/GEOMImpl/GEOMImpl_IInsertOperations.hxx
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
src/GEOM_I/GEOM_IInsertOperations_i.cc
src/GEOM_I/GEOM_IInsertOperations_i.hh
src/GEOM_I/GEOM_Object_i.cc
src/GEOM_I/GEOM_Object_i.hh
src/GEOM_SWIG/geompyDC.py

index f239246ad98af8e549f0a1d2cce76c76ba86216e..96eed9a93ac48fddd94b0ddf8cb251b46f2286d9 100644 (file)
 #include <TDataStd_ChildNodeIterator.hxx>
 #include <TFunction_Driver.hxx>
 #include <TFunction_DriverTable.hxx>
+#include <TDataStd_HArray1OfByte.hxx>
+#include <TDataStd_ByteArray.hxx>
+#include <TDataStd_UAttribute.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <TDataStd_Comment.hxx>
 
 #include <TopExp.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
@@ -122,10 +127,12 @@ void ReplaceEntriesByNames (TCollection_AsciiString&                  theScript,
                            Resource_DataMapOfAsciiStringAsciiString& theEntryToBadName,
                             TColStd_SequenceOfAsciiString&            theObjListToPublish);
 
-void AddObjectColors (const Handle(TDocStd_Document)&                 theDoc,
+void AddObjectColors (int                                             theDocID,
                      TCollection_AsciiString&                        theScript,
                      const Resource_DataMapOfAsciiStringAsciiString& theObjectNames);
 
+void AddTextures (int theDocID, TCollection_AsciiString& theScript);
+
 void PublishObject (const TCollection_AsciiString&                  theEntry,
                    const TCollection_AsciiString&                  theName,
                    const Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
@@ -135,6 +142,16 @@ void PublishObject (const TCollection_AsciiString&                  theEntry,
                    std::map< int, std::string >&                   theEntryToCommandMap,
                    std::set<std::string>&                          theMapOfPublished);
 
+//=======================================================================
+//function : GetTextureGUID
+//purpose  :
+//=======================================================================
+const Standard_GUID& GEOM_Engine::GetTextureGUID()
+{
+  static Standard_GUID anID("FF1BBB01-5D14-4df2-980B-3A668264EA17");
+  return anID;
+}
+
 //=============================================================================
 /*!
  *  GetEngine
@@ -503,11 +520,14 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
 
   if (aDoc.IsNull()) return TCollection_AsciiString("def RebuildData(theStudy): pass\n");
 
-  aScript  = "import geompy\n";
+  aScript  = "import GEOM\n";
+  aScript += "import geompy\n";
   aScript += "import math\n";
   aScript += "import SALOMEDS\n\n";
   aScript += "def RebuildData(theStudy):";
-  aScript += "\n\tgeompy.init_geom(theStudy)";
+  aScript += "\n\tgeompy.init_geom(theStudy)\n";
+
+  AddTextures(theDocID, aScript);
 
   Standard_Integer posToInsertGlobalVars = aScript.Length() + 1;
 
@@ -615,7 +635,7 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
   aScript += aFuncScript;
 
   // ouv : NPAL12872
-  AddObjectColors( aDoc, aScript, theObjectNames );
+  AddObjectColors( theDocID, aScript, theObjectNames );
 
   // Make script to publish in study
   if ( isPublished )
@@ -695,6 +715,117 @@ Handle(TColStd_HSequenceOfAsciiString) GEOM_Engine::GetAllDumpNames() const
   return aRetSeq;
 }
 
+#define TEXTURE_LABEL_ID       1
+#define TEXTURE_LABEL_FILE     2
+#define TEXTURE_LABEL_WIDTH    3
+#define TEXTURE_LABEL_HEIGHT   4
+#define TEXTURE_LABEL_DATA     5
+
+int GEOM_Engine::addTexture(int theDocID, int theWidth, int theHeight, 
+                           const Handle(TDataStd_HArray1OfByte)& theTexture,
+                           const TCollection_AsciiString& theFileName)
+{
+  Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
+  Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
+
+  // NPAL18604: use existing label to decrease memory usage,
+  //            if this label has been freed (object deleted)
+  bool useExisting = false;
+  TDF_Label aChild;
+  if (_freeLabels.find(theDocID) != _freeLabels.end()) {
+    std::list<TDF_Label>& aFreeLabels = _freeLabels[theDocID];
+    if (!aFreeLabels.empty()) {
+      useExisting = true;
+      aChild = aFreeLabels.front();
+      aFreeLabels.pop_front();
+    }
+  }
+  if (!useExisting) {
+    // create new label
+    aChild = TDF_TagSource::NewChild(aDoc->Main());
+  }
+
+  aChild.ForgetAllAttributes(Standard_True);
+  Handle(TDataStd_TreeNode) node;
+  if ( !aChild.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), node ) )
+    node = TDataStd_TreeNode::Set(aChild);
+  TDataStd_UAttribute::Set(aChild, GetTextureGUID());
+
+  static int aTextureID = 0;
+
+  TDataStd_Integer::Set(aChild.FindChild(TEXTURE_LABEL_ID),     ++aTextureID);
+  TDataStd_Comment::Set(aChild.FindChild(TEXTURE_LABEL_FILE),   theFileName);
+  TDataStd_Integer::Set(aChild.FindChild(TEXTURE_LABEL_WIDTH),  theWidth);
+  TDataStd_Integer::Set(aChild.FindChild(TEXTURE_LABEL_HEIGHT), theHeight);
+
+  Handle(TDataStd_ByteArray) anAttr =
+    TDataStd_ByteArray::Set(aChild.FindChild(TEXTURE_LABEL_DATA), 
+                           theTexture.IsNull() ? 0 : theTexture->Lower(),
+                           theTexture.IsNull() ? 0 : theTexture->Upper());
+  anAttr->ChangeArray(theTexture);
+
+  return aTextureID;
+}
+
+Handle(TDataStd_HArray1OfByte) GEOM_Engine::getTexture(int theDocID, int theTextureID,
+                                                      int& theWidth, int& theHeight,
+                                                      TCollection_AsciiString& theFileName)
+{
+  Handle(TDataStd_HArray1OfByte) anArray;
+  theWidth = theHeight = 0;
+
+  Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
+
+  TDF_ChildIterator anIterator(aDoc->Main(), Standard_True);
+  bool found = false;
+  for (; anIterator.More() && !found; anIterator.Next()) {
+    TDF_Label aTextureLabel = anIterator.Value();
+    if (aTextureLabel.IsAttribute( GetTextureGUID())) {
+      TDF_Label anIDLabel = aTextureLabel.FindChild(TEXTURE_LABEL_ID, Standard_False);
+      Handle(TDataStd_Integer) anIdAttr;
+      if(!anIDLabel.IsNull() && anIDLabel.FindAttribute(TDataStd_Integer::GetID(), anIdAttr) && 
+        anIdAttr->Get() == theTextureID) {
+       TDF_Label aFileLabel   = aTextureLabel.FindChild(TEXTURE_LABEL_FILE,    Standard_False);
+       TDF_Label aWidthLabel  = aTextureLabel.FindChild(TEXTURE_LABEL_WIDTH,   Standard_False);
+       TDF_Label aHeightLabel = aTextureLabel.FindChild(TEXTURE_LABEL_HEIGHT,  Standard_False);
+       TDF_Label aDataLabel   = aTextureLabel.FindChild(TEXTURE_LABEL_DATA,    Standard_False);
+       Handle(TDataStd_Integer) aWidthAttr, aHeightAttr;
+       Handle(TDataStd_ByteArray) aTextureAttr;
+       Handle(TDataStd_Comment) aFileAttr;
+       if (!aWidthLabel.IsNull()  && aWidthLabel.FindAttribute(TDataStd_Integer::GetID(),  aWidthAttr) &&
+           !aHeightLabel.IsNull() && aHeightLabel.FindAttribute(TDataStd_Integer::GetID(), aHeightAttr) &&
+           !aDataLabel.IsNull()   && aDataLabel.FindAttribute(TDataStd_ByteArray::GetID(), aTextureAttr)) {
+         theWidth = aWidthAttr->Get();
+         theHeight = aHeightAttr->Get();
+         anArray = aTextureAttr->InternalArray();
+       }
+       if (!aFileLabel.IsNull() && aFileLabel.FindAttribute(TDataStd_Comment::GetID(), aFileAttr))
+         theFileName = aFileAttr->Get();
+       found = true;
+      }
+    }
+  }
+  return anArray;
+}
+
+std::list<int> GEOM_Engine::getAllTextures(int theDocID)
+{
+  std::list<int> id_list;
+
+  Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
+
+  TDF_ChildIterator anIterator(aDoc->Main(), Standard_True);
+  for (; anIterator.More(); anIterator.Next()) {
+    TDF_Label aTextureLabel = anIterator.Value();
+    if (aTextureLabel.IsAttribute( GetTextureGUID())) {
+      TDF_Label anIDLabel = aTextureLabel.FindChild(TEXTURE_LABEL_ID, Standard_False);
+      Handle(TDataStd_Integer) anIdAttr;
+      if(!anIDLabel.IsNull() && anIDLabel.FindAttribute(TDataStd_Integer::GetID(), anIdAttr))
+       id_list.push_back((int)anIdAttr->Get());
+    }
+  }
+  return id_list;
+}
 
 //===========================================================================
 //                     Internal functions
@@ -1164,10 +1295,13 @@ void ReplaceEntriesByNames (TCollection_AsciiString&                  theScript,
  *  AddObjectColors: Add color to objects
  */
 //=============================================================================
-void AddObjectColors (const Handle(TDocStd_Document)&                 theDoc,
+void AddObjectColors (int                                             theDocID,
                      TCollection_AsciiString&                        theScript,
                      const Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
 {
+  GEOM_Engine* engine = GEOM_Engine::GetEngine();
+  Handle(TDocStd_Document) aDoc = engine->GetDocument(theDocID);
+
   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt;
   for (anEntryToNameIt.Initialize( theObjectNames );
        anEntryToNameIt.More();
@@ -1177,7 +1311,7 @@ void AddObjectColors (const Handle(TDocStd_Document)&                 theDoc,
     const TCollection_AsciiString& aName = anEntryToNameIt.Value();
 
     TDF_Label L;
-    TDF_Tool::Label( theDoc->GetData(), aEntry, L );
+    TDF_Tool::Label( aDoc->GetData(), aEntry, L );
     if ( L.IsNull() )
       continue;
 
@@ -1200,6 +1334,108 @@ void AddObjectColors (const Handle(TDocStd_Document)&                 theDoc,
       aCommand += aName + ".SetColor(SALOMEDS.Color(" + aColor.R + "," + aColor.G + "," + aColor.B + "))";
       theScript += aCommand.ToCString();
     }
+    
+    Aspect_TypeOfMarker aMarkerType = obj->GetMarkerType();
+    if (aMarkerType >= Aspect_TOM_POINT && aMarkerType < Aspect_TOM_USERDEFINED) {
+      TCollection_AsciiString aCommand( "\n\t" );
+      aCommand += aName + ".SetMarkerStd(";
+      switch (aMarkerType) {
+      case Aspect_TOM_POINT:   aCommand += "GEOM.MT_POINT";   break;
+      case Aspect_TOM_PLUS:    aCommand += "GEOM.MT_PLUS";    break;
+      case Aspect_TOM_STAR:    aCommand += "GEOM.MT_STAR";    break;
+      case Aspect_TOM_O:       aCommand += "GEOM.MT_O";       break;
+      case Aspect_TOM_X:       aCommand += "GEOM.MT_X";       break;
+      case Aspect_TOM_O_POINT: aCommand += "GEOM.MT_O_POINT"; break;
+      case Aspect_TOM_O_PLUS:  aCommand += "GEOM.MT_O_PLUS";  break;
+      case Aspect_TOM_O_STAR:  aCommand += "GEOM.MT_O_STAR";  break;
+      case Aspect_TOM_O_X:     aCommand += "GEOM.MT_O_X";     break;
+      case Aspect_TOM_BALL:    aCommand += "GEOM.MT_BALL";    break;
+      case Aspect_TOM_RING1:   aCommand += "GEOM.MT_RING1";   break;
+      case Aspect_TOM_RING2:   aCommand += "GEOM.MT_RING2";   break;
+      case Aspect_TOM_RING3:   aCommand += "GEOM.MT_RING3";   break;
+      default:                 aCommand += "GEOM.MT_NONE";    break; // just for completeness, should not get here
+      }
+      aCommand += ", ";
+      int aSize = (int)( obj->GetMarkerSize()/0.5 ) - 1;
+      switch (aSize) {
+      case  1: aCommand += "GEOM.MS_10";   break;
+      case  2: aCommand += "GEOM.MS_15";   break;
+      case  3: aCommand += "GEOM.MS_20";   break;
+      case  4: aCommand += "GEOM.MS_25";   break;
+      case  5: aCommand += "GEOM.MS_30";   break;
+      case  6: aCommand += "GEOM.MS_35";   break;
+      case  7: aCommand += "GEOM.MS_40";   break;
+      case  8: aCommand += "GEOM.MS_45";   break;
+      case  9: aCommand += "GEOM.MS_50";   break;
+      case 10: aCommand += "GEOM.MS_55";   break;
+      case 11: aCommand += "GEOM.MS_60";   break;
+      case 12: aCommand += "GEOM.MS_65";   break;
+      case 13: aCommand += "GEOM.MS_70";   break;
+      default: aCommand += "GEOM.MS_NONE"; break;
+      }
+      aCommand += ");";
+      theScript += aCommand.ToCString();
+    }
+    else if (aMarkerType == Aspect_TOM_USERDEFINED) {
+      int aMarkerTextureID = obj->GetMarkerTexture();
+      if (aMarkerTextureID >= 0) {
+       TCollection_AsciiString aCommand( "\n\t" );
+       aCommand += aName + ".SetMarkerTexture(texture_map[";
+       aCommand += aMarkerTextureID;
+       aCommand += "]);";
+       theScript += aCommand.ToCString();
+      }
+    }
+  }
+}
+
+static TCollection_AsciiString pack_data(const Handle(TDataStd_HArray1OfByte)& aData )
+{
+  TCollection_AsciiString stream;
+  if (!aData.IsNull()) {
+    for (Standard_Integer i = aData->Lower(); i <= aData->Upper(); i++) {
+      Standard_Byte byte = aData->Value(i);
+      TCollection_AsciiString strByte = "";
+      for (int j = 0; j < 8; j++)
+       strByte.Prepend((byte & (1<<j)) ? "1" : "0");
+      stream += strByte;
+    }
+  }
+  return stream;
+}
+
+void AddTextures (int theDocID, TCollection_AsciiString& theScript)
+{
+  GEOM_Engine* engine = GEOM_Engine::GetEngine();
+  std::list<int> allTextures = engine->getAllTextures(theDocID);
+  std::list<int>::const_iterator it;
+
+  if (allTextures.size() > 0) {
+    theScript += "\n\ttexture_map = {}\n";
+    
+    for (it = allTextures.begin(); it != allTextures.end(); ++it) {
+      if (*it <= 0) continue;
+      Standard_Integer aWidth, aHeight;
+      TCollection_AsciiString aFileName;
+      Handle(TDataStd_HArray1OfByte) aTexture = engine->getTexture(theDocID, *it, aWidth, aHeight, aFileName);
+      if (aWidth > 0 && aHeight > 0 && !aTexture.IsNull() && aTexture->Length() > 0 ) {
+       TCollection_AsciiString aCommand = "\n\t";
+       aCommand += "texture_map["; aCommand += *it; aCommand += "] = ";
+       if (aFileName != "" ) {
+         aCommand += "geompy.LoadTexture(\"";
+         aCommand += aFileName.ToCString();
+         aCommand += "\")";
+       }
+       else {
+         aCommand += "geompy.AddTexture(";
+         aCommand += aWidth; aCommand += ", "; aCommand += aHeight; aCommand += ", \"";
+         aCommand += pack_data(aTexture);
+         aCommand += "\")";
+       }
+       theScript += aCommand;
+      }
+    }
+    theScript += "\n";
   }
 }
 
index c901123b604ff4923451d08bdde802b31c9f3804..6ec146c926506b2e3790637bbe88436420a1eb4a 100644 (file)
@@ -37,6 +37,8 @@
 #include <list>
 #include <vector>
 
+class Handle_TDataStd_HArray1OfByte;
+
 struct TVariable{
   TCollection_AsciiString myVariable;
   bool isVariable;
@@ -130,6 +132,16 @@ class GEOM_Engine
 
   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) GetAllDumpNames() const;
 
+  int addTexture(int theDocID, int theWidth, int theHeight,
+                const Handle(TDataStd_HArray1OfByte)& theTexture,
+                const TCollection_AsciiString& theFileName = "");
+  Handle(TDataStd_HArray1OfByte) getTexture(int theDocID, int theTextureID,
+                                           int& theWidth, int& theHeight,
+                                           TCollection_AsciiString& theFileName);
+  std::list<int> getAllTextures(int theDocID);
+
+  static const Standard_GUID& GetTextureGUID();
+
  protected:
   Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine);       
   
index b2ca175f4d84ac9307826130cd1811bff54c4cb2..38025ab067ac88f00b8ae87b14695d3ca0d17bb4 100644 (file)
 #include <TDocStd_Owner.hxx>
 #include <TDocStd_Document.hxx>
 #include <TDataStd_Integer.hxx>
+#include <TDataStd_Real.hxx>
 #include <TDataStd_ChildNodeIterator.hxx>
 #include <TDataStd_UAttribute.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDataStd_Comment.hxx>
 #include <TDataStd_RealArray.hxx>
+#include <TDataStd_ByteArray.hxx>
 #include <TColStd_HArray1OfReal.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 #include <TopExp.hxx>
 
 #define FUNCTION_LABEL(theNb) (_label.FindChild(1).FindChild((theNb)))
-#define TYPE_LABEL 2
-#define FREE_LABEL 3
-#define TIC_LABEL  4
+#define TYPE_LABEL       2
+#define FREE_LABEL       3
+#define TIC_LABEL        4
 #define COLOR_LABEL      5
 #define AUTO_COLOR_LABEL 6
+#define MARKER_LABEL     7
+
+#define MARKER_LABEL_TYPE 1
+#define MARKER_LABEL_SIZE 2
+#define MARKER_LABEL_ID   3
 
 //=======================================================================
 //function : GetObjectID
@@ -368,6 +375,96 @@ CORBA::Boolean GEOM_Object::GetAutoColor()
   return anAutoColor->Get();
 }
 
+//=============================================================================
+/*!
+ *  SetMarkerStd
+ */
+//=============================================================================
+void GEOM_Object::SetMarkerStd(const Aspect_TypeOfMarker theType, double theSize)
+{
+  TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL);
+  TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_TYPE), (int)theType);
+  TDataStd_Real::Set(aMarkerLabel.FindChild(MARKER_LABEL_SIZE), theSize);
+}
+  
+//=============================================================================
+/*!
+ *  SetMarkerTexture
+ */
+//=============================================================================
+void GEOM_Object::SetMarkerTexture(int theTextureId)
+{
+  TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL);
+  TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_TYPE), (int)Aspect_TOM_USERDEFINED);
+  TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_ID),   theTextureId);
+}
+
+//=============================================================================
+/*!
+ *  GetMarkerType
+ */
+//=============================================================================
+Aspect_TypeOfMarker GEOM_Object::GetMarkerType()
+{
+  Standard_Integer aType = -1;
+  TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
+  if(!aMarkerLabel.IsNull()) {
+    TDF_Label aTypeLabel = aMarkerLabel.FindChild(MARKER_LABEL_TYPE, Standard_False);
+    Handle(TDataStd_Integer) aTypeAttr;
+    if (!aTypeLabel.IsNull() && aTypeLabel.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr))
+      aType = aTypeAttr->Get();
+  }
+  return (Aspect_TypeOfMarker)aType;
+}
+
+//=============================================================================
+/*!
+ *  GetMarkerSize
+ */
+//=============================================================================
+double GEOM_Object::GetMarkerSize()
+{
+  Standard_Real aSize = 0.;
+  TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
+  if(!aMarkerLabel.IsNull()) {
+    TDF_Label aSizeLabel = aMarkerLabel.FindChild(MARKER_LABEL_SIZE, Standard_False);
+    Handle(TDataStd_Real) aSizeAttr;
+    if (!aSizeLabel.IsNull() && aSizeLabel.FindAttribute(TDataStd_Real::GetID(), aSizeAttr))
+      aSize = aSizeAttr->Get();
+  }
+  return aSize;
+}
+
+//=============================================================================
+/*!
+ *  GetMarkerTexture
+ */
+//=============================================================================
+int GEOM_Object::GetMarkerTexture()
+{
+  Standard_Integer anId = 0;
+  if ( GetMarkerType() == Aspect_TOM_USERDEFINED) {
+    TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
+    if(!aMarkerLabel.IsNull()) {
+      TDF_Label aTypeLabel = aMarkerLabel.FindChild(MARKER_LABEL_ID, Standard_False);
+      Handle(TDataStd_Integer) anIdAttr;
+      if (!aTypeLabel.IsNull() && aTypeLabel.FindAttribute(TDataStd_Integer::GetID(), anIdAttr))
+       anId = anIdAttr->Get();
+    }
+  }
+  return anId;
+}
+
+//=============================================================================
+/*!
+ *  SetAuxData
+ */
+//=============================================================================
+void GEOM_Object::UnsetMarker()
+{
+  SetMarkerStd((Aspect_TypeOfMarker)-1, 0.);
+}
+
 //=============================================================================
 /*!
  *  SetAuxData
index dd2f73ea2d2e66b3a34e5b7f46a100c3351783e2..66f93f64295cebff9376c2894461a93b1e885aad 100644 (file)
@@ -55,6 +55,9 @@
 #ifndef _TCollection_AsciiString_HeaderFile
 #include <TCollection_AsciiString.hxx>
 #endif
+#ifndef _Aspect_TypeOfMarker_HeaderFile
+#include <Aspect_TypeOfMarker.hxx>
+#endif
 
 #include "SALOMEconfig.h"
 #include CORBA_SERVER_HEADER(SALOMEDS)
@@ -215,6 +218,24 @@ class GEOM_Object : public MMgt_TShared
   //Returns a flag of auto color mode of this GEOM_Object
   Standard_EXPORT CORBA::Boolean GetAutoColor();
 
+  //Sets predefined point marker texture
+  Standard_EXPORT void SetMarkerStd(const Aspect_TypeOfMarker theType, double theSize);
+  
+  //Sets custom point marker texture
+  Standard_EXPORT void SetMarkerTexture(int theTextureId);
+
+  //Gets point marker type
+  Standard_EXPORT Aspect_TypeOfMarker GetMarkerType();
+
+  //Gets point marker scale factor / size
+  Standard_EXPORT double GetMarkerSize();
+
+  //Gets custom marker texture ID
+  Standard_EXPORT int GetMarkerTexture();
+
+  //Unsets point marker
+  Standard_EXPORT void UnsetMarker();
+
   //Sets an auxiliary data
   Standard_EXPORT void SetAuxData(const char* theData);
 
index 61b86c34c9bf7d4e840ce0a8b119f7f1f1a74f94..435419768671e3ba5bde36390feb90ad1698cb92 100644 (file)
@@ -79,6 +79,7 @@
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 
 // VTK Includes
 #include <vtkActorCollection.h>
@@ -588,54 +589,54 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
           }
         }
        else
+       {
+         if ( myShape.ShapeType() == TopAbs_VERTEX )
          {
-           if ( myShape.ShapeType() == TopAbs_VERTEX )
-             {
-               col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
-               anAspect->SetColor( aColor );
-                anAspect->SetScale( myScaleOfMarker );
-                anAspect->SetTypeOfMarker( myTypeOfMarker );
-                AISShape->Attributes()->SetPointAspect( anAspect );
-             }
-           else
-             {
-               // Set line aspect
-               col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetLineAspect( anAspect );
-
-               // Set unfree boundaries aspect
-               anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
-
-               // Set free boundaries aspect
-               col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               anAspect = AISShape->Attributes()->FreeBoundaryAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
-
-               // Set wire aspect
-               col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               anAspect = AISShape->Attributes()->WireAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetWireAspect( anAspect );
-
-                // bug [SALOME platform 0019868]
-                // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
-                AISShape->SetOwnDeviationAngle( 10*PI/180 );
-             }
+           col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+           anAspect->SetColor( aColor );
+           anAspect->SetScale( myScaleOfMarker );
+           anAspect->SetTypeOfMarker( myTypeOfMarker );
+           AISShape->Attributes()->SetPointAspect( anAspect );
          }
+         else
+         {
+           // Set line aspect
+           col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetLineAspect( anAspect );
+           
+           // Set unfree boundaries aspect
+           anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
+           
+           // Set free boundaries aspect
+           col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           anAspect = AISShape->Attributes()->FreeBoundaryAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
+           
+           // Set wire aspect
+           col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           anAspect = AISShape->Attributes()->WireAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetWireAspect( anAspect );
+           
+           // bug [SALOME platform 0019868]
+           // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
+           AISShape->SetOwnDeviationAngle( 10*PI/180 );
+         }
+       }
 
         if ( HasWidth() )
           AISShape->SetWidth( GetWidth() );
@@ -657,7 +658,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
           AISShape->SetOwner( anObj );
         }
 
-       // Get color from GEOM_Object
+       // Get color and other properties from GEOM_Object
        SUIT_Session* session = SUIT_Session::session();
        SUIT_Application* app = session->activeApplication();
        if ( app )
@@ -731,6 +732,36 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
                         AISShape->Attributes()->SetPointAspect( anAspect );
                       }
                    }
+                   // ... marker type
+                   GEOM::marker_type aType = aGeomObject->GetMarkerType();
+                   GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
+                   if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
+                     Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
+                     double aMSize = ((int)aSize+1)*0.5;
+                     Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+                     anAspect->SetScale( aMSize );
+                     anAspect->SetTypeOfMarker( aMType );
+                     Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
+                     if ( hasColor )
+                       aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
+                     anAspect->SetColor( aQuanColor );
+                     AISShape->Attributes()->SetPointAspect( anAspect );
+                   }
+                   else if ( aType == GEOM::MT_USER ) {
+                     int aTextureId = aGeomObject->GetMarkerTexture();
+                     Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
+                     if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
+                     Standard_Integer aWidth, aHeight;
+                     Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTextureAspect( getStudy(), aTextureId, aWidth, aHeight );
+                     if ( !aTexture.IsNull() ) {
+                       static int TextureId = 0;
+                       Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor,
+                                                                                        ++TextureId,
+                                                                                        aWidth, aHeight,
+                                                                                        aTexture );
+                       AISShape->Attributes()->SetPointAspect( aTextureAspect );
+                     }
+                   }
                  }
                }
              }
index 81efb22a1ccb30a92be7de5d61cd6c271bfd0858..cfb50c82bb2c10aba2119d503f156b59ab187d5b 100644 (file)
@@ -80,6 +80,7 @@
 #include <Aspect_TypeOfMarker.hxx>
 #include <OSD_SharedLibrary.hxx>
 #include <NCollection_DataMap.hxx>
+#include <Graphic3d_HArray1OfBytes.hxx>
 
 #include <utilities.h>
 
@@ -96,7 +97,7 @@ extern "C" {
   }
 }
 
-
+GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
 
 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
 
@@ -1462,6 +1463,32 @@ QString GeometryGUI::engineIOR() const
   return "";
 }
 
+Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTextureAspect( SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight )
+{
+  theWidth = theHeight = 0;
+  Handle(Graphic3d_HArray1OfBytes) aTexture;
+  if ( theStudy ) {
+    TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
+    aTexture = aTextureMap[ theId ];
+    if ( aTexture.IsNull() ) {
+      GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
+      if ( !aInsOp->_is_nil() ) {
+       CORBA::Long aWidth, aHeight;
+       SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
+       if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
+         theWidth  = aWidth;
+         theHeight = aHeight;
+         aTexture  = new Graphic3d_HArray1OfBytes( 1, aStream->length() );
+         for ( int i = 0; i < aStream->length(); i++ )
+           aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
+         aTextureMap[ theId ] = aTexture;
+       }
+      }
+    }
+  }
+  return aTexture;
+}
+
 LightApp_Selection* GeometryGUI::createSelection() const
 {
   return new GEOMGUI_Selection();
index a82efcb25bf99c14dadee59c352c46c4360f9158..67a793b7ec3a49c5294234339a33b32ebb6ebac9 100644 (file)
@@ -41,6 +41,7 @@
 
 // OCCT Includes
 #include <gp_Ax3.hxx>
+#include <Graphic3d_HArray1OfBytes.hxx>
 
 // IDL headers
 #include "SALOMEconfig.h"
@@ -54,6 +55,7 @@ class GEOMGUI_OCCSelector;
 class LightApp_VTKSelector;
 class LightApp_Selection;
 class SUIT_ViewManager;
+class SalomeApp_Study;
 
 //=================================================================================
 // class    : GeometryGUI
@@ -74,6 +76,8 @@ public:
   virtual void                initialize( CAM_Application* );
   virtual QString             engineIOR() const;
 
+  static Handle(Graphic3d_HArray1OfBytes) getTextureAspect( SalomeApp_Study*, int, int&, int& );
+
   static bool                 InitGeomGen();   //BugID IPAL9186: SRN: To be called by Python scripts
 
   static  GEOM::GEOM_Gen_var  GetGeomGen();//        { return GeometryGUI::myComponentGeom; }
@@ -159,7 +163,12 @@ private:
 
 public:
   static GEOM::GEOM_Gen_var   myComponentGeom;   // GEOM engine!!!
+
 private:  
+
+  typedef QMap<long, Handle(Graphic3d_HArray1OfBytes)> TextureMap;
+  typedef QMap<long, TextureMap> StudyTextureMap;
+  
   GUIMap                      myGUIMap;          // GUI libraries map
   QDialog*                    myActiveDialogBox; // active dialog box
   GEOM_Client                 myShapeReader;     // geom shape reader
@@ -167,6 +176,7 @@ private:
   int                         myState;           // identify a method
   gp_Ax3                      myWorkingPlane;
   QMap<int,QString>           myRules;           // popup rules
+  static StudyTextureMap      myTextureMap;      // texture map
 
   QList<GEOMGUI_OCCSelector*>  myOCCSelectors;
   QList<LightApp_VTKSelector*> myVTKSelectors;
@@ -174,7 +184,7 @@ private:
   LightApp_Displayer*         myDisplayer;
   int                         myLocalSelectionMode; //Select Only
 
-friend class DisplayGUI;
+  friend class DisplayGUI;
 };
 
 #endif
index 884c457cff9047a88f9020c76b83db5764e0618b..80f4a296265b4f3d26cdcbd0884fd7be34811772 100644 (file)
@@ -48,6 +48,7 @@
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Tool.hxx>
 #include <gp_Pnt.hxx>
+#include <TDataStd_HArray1OfByte.hxx>
 
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
@@ -543,3 +544,98 @@ Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
   return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
           myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
 }
+
+int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
+{
+  SetErrorCode(KO);
+
+  if (theTextureFile.IsEmpty()) return 0;
+
+  Handle(TDataStd_HArray1OfByte) aTexture;
+
+  FILE* fp = fopen(theTextureFile.ToCString(), "r");
+  if (!fp) return 0;
+
+  std::list<std::string> lines;
+  char buffer[4096];
+  int maxlen = 0;
+  while (!feof(fp)) {
+    if ((fgets(buffer, 4096, fp)) == NULL) break;
+    int aLen = strlen(buffer);
+    if (buffer[aLen-1] == '\n') buffer[aLen-1] = '\0';
+    lines.push_back(buffer);
+    maxlen = std::max(maxlen, (int)strlen(buffer));
+  }
+
+  fclose(fp);
+
+  int lenbytes = maxlen/8;
+  if (maxlen%8) lenbytes++;
+
+  if (lenbytes == 0 || lines.empty())
+    return 0;
+
+  std::list<unsigned char> bytedata;
+  std::list<std::string>::const_iterator it;
+  for (it = lines.begin(); it != lines.end(); ++it) {
+    std::string line = *it;
+    int lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8;
+    for (int i = 0; i < lenline/8; i++) {
+      unsigned char byte = 0;
+      for (int j = 0; j < 8; j++)
+       byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 );
+      bytedata.push_back(byte);
+    }
+    for (int i = lenline/8; i < lenbytes; i++)
+      bytedata.push_back((unsigned char)0);
+  }
+
+  if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes)
+    return 0;
+
+  aTexture = new TDataStd_HArray1OfByte(1, lines.size()*lenbytes);
+  std::list<unsigned char>::iterator bdit;
+  int i;
+  for (i = 1, bdit = bytedata.begin(); bdit != bytedata.end(); ++bdit, ++i)
+    aTexture->SetValue(i, (Standard_Byte)(*bdit));
+
+  int aTextureId = GetEngine()->addTexture(GetDocID(), lenbytes*8, lines.size(), aTexture, theTextureFile);
+  if (aTextureId > 0) SetErrorCode(OK);
+  return aTextureId;
+}
+  
+int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, 
+                                          const Handle(TDataStd_HArray1OfByte)& theTexture)
+{
+  SetErrorCode(KO);
+  int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture);
+  if (aTextureId > 0) SetErrorCode(OK);
+  return aTextureId;
+}
+
+Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
+                                                                     int& theWidth, int& theHeight)
+{
+  SetErrorCode(KO);
+  
+  Handle(TDataStd_HArray1OfByte) aTexture;
+  theWidth = theHeight = 0;
+  TCollection_AsciiString aFileName;
+
+  if (theTextureId <= 0)
+    return aTexture;
+
+  aTexture = GetEngine()->getTexture(GetDocID(), theTextureId, theWidth, theHeight, aFileName);
+
+  if (theWidth > 0 && theHeight > 0 && aTexture->Length() > 0) SetErrorCode(OK);
+
+  return aTexture;
+}
+
+std::list<int> GEOMImpl_IInsertOperations::GetAllTextures()
+{
+  SetErrorCode(KO);
+  std::list<int> id_list = GetEngine()->getAllTextures(GetDocID());
+  SetErrorCode(OK);
+  return id_list;
+}
index aba0c227f6e57d602c9f5dc1315e042c787232f3..51d2ed350bf8cb60cd0f926cb7a49eb068d838f7 100644 (file)
@@ -30,6 +30,9 @@
 #include <TColStd_HSequenceOfAsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
 #include <Resource_Manager.hxx>
+#include <list>
+
+class Handle_TDataStd_HArray1OfByte;
 
 class GEOMImpl_IInsertOperations : public GEOM_IOperations {
  public:
@@ -56,6 +59,16 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
                                                 const TCollection_AsciiString& theFormat,
                                                 Handle(TCollection_HAsciiString)& theLibName);
 
+  Standard_EXPORT int LoadTexture(const TCollection_AsciiString& theTextureFile);
+  
+  Standard_EXPORT int AddTexture(int theWidth, int theHeight, 
+                                const Handle(TDataStd_HArray1OfByte)& theTexture);
+
+  Standard_EXPORT Handle(TDataStd_HArray1OfByte) GetTexture(int theTextureId, 
+                                                           int& theWidth, int& theHeight);
+
+  Standard_EXPORT std::list<int> GetAllTextures();
+  
  private:
   Standard_Boolean InitResMgr ();
 
index bc7e8fd23675299e05ad4e67cd0c23c5d6b44452..ea3251f1920ea31668ec1a3a2a83cfae03c606ba 100644 (file)
@@ -70,6 +70,7 @@
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_HArray1OfBytes.hxx>
 
 // QT Includes
 #include <QColorDialog>
@@ -257,7 +258,15 @@ void GEOMToolsGUI::OnAutoColor()
       Standard_Real aCurScale;
       Aspect_TypeOfMarker aCurTypeOfMarker;
       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
-      aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
+      if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
+       aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
+      }
+      else {
+       Standard_Integer aWidth, aHeight;
+       aCurPointAspect->GetTextureSize( aWidth, aHeight );
+       Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
+       aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
+      }
       ic->SetLocalAttributes( io, aCurDrawer );
 
       io->SetColor( aQuanColor );
@@ -348,7 +357,15 @@ void GEOMToolsGUI::OnColor()
                  Standard_Real aCurScale;
                  Aspect_TypeOfMarker aCurTypeOfMarker;
                  aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
-                 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
+                 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
+                   aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
+                 }
+                 else {
+                   Standard_Integer aWidth, aHeight;
+                   aCurPointAspect->GetTextureSize( aWidth, aHeight );
+                   Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
+                   aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aColor, 1, aWidth, aHeight, aTexture ) );
+                 }
                  ic->SetLocalAttributes(io, aCurDrawer);
                  
                  io->SetColor( aColor );
index b32b3eb717457407857f29ab3b4e210d04ab90ff..c5570650e29f0f78075416215f28ca22b108d241 100644 (file)
@@ -35,6 +35,7 @@
 #include "GEOM_Object.hxx"
 
 #include <TColStd_HSequenceOfAsciiString.hxx>
+#include <TDataStd_HArray1OfByte.hxx>
 
 //=============================================================================
 /*!
@@ -215,3 +216,52 @@ void GEOM_IInsertOperations_i::ExportTranslators
   theFormats  = aFormatsArray._retn();
   thePatterns = aPatternsArray._retn();
 }
+
+CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
+{
+  GetOperations()->SetNotDone();
+  return GetOperations()->LoadTexture( theTextureFile );
+}
+
+CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
+                                                const SALOMEDS::TMPFile& theTexture)
+{
+  GetOperations()->SetNotDone();
+  Handle(TDataStd_HArray1OfByte) aTexture;
+  if ( theTexture.length() > 0 ) {
+    aTexture = new TDataStd_HArray1OfByte( 1, theTexture.length() );
+    for ( int i = 0; i < theTexture.length(); i++ )
+      aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
+  }
+  return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
+}
+
+SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID, 
+                                                       CORBA::Long& theWidth,
+                                                       CORBA::Long& theHeight)
+{
+  int aWidth, aHeight;
+  Handle(TDataStd_HArray1OfByte) aTextureImpl = GetOperations()->GetTexture( theID, aWidth, aHeight );
+  theWidth  = aWidth;
+  theHeight = aHeight;
+  SALOMEDS::TMPFile_var aTexture;
+  if ( !aTextureImpl.IsNull() ) {
+    aTexture = new SALOMEDS::TMPFile;
+    aTexture->length( aTextureImpl->Length() );
+    for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
+      aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
+  }
+  return aTexture._retn();
+}
+
+GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
+{
+  std::list<int> localIDs = GetOperations()->GetAllTextures();
+  GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
+  anIDs->length(localIDs.size());
+  std::list<int>::const_iterator anIt;
+  int i = 0;
+  for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
+    anIDs[i] = *anIt;
+  return anIDs._retn();
+}
index da29eabf0600ea325980119fabc6fe97864b97d0..49a4269814373ed24306b0e5ef3bf502054eb20c 100644 (file)
@@ -27,6 +27,7 @@
 #include <SALOMEconfig.h>
 
 #include CORBA_SERVER_HEADER(GEOM_Gen)
+#include CORBA_CLIENT_HEADER(SALOMEDS)
 #include "GEOM_IOperations_i.hh"
 #include "GEOM_Object_i.hh"
 
@@ -56,6 +57,15 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i :
   void ExportTranslators (GEOM::string_array_out theFormats,
                          GEOM::string_array_out thePatterns);
 
+  CORBA::Long LoadTexture(const char* theTextureFile);
+  CORBA::Long AddTexture(CORBA::Long theWidth, CORBA::Long theHeight, 
+                        const SALOMEDS::TMPFile& theTexture);
+  SALOMEDS::TMPFile* GetTexture(CORBA::Long theID, 
+                               CORBA::Long& theWidth,
+                               CORBA::Long& theHeight);
+
+  GEOM::ListOfLong* GetAllTextures();
+
   ::GEOMImpl_IInsertOperations* GetOperations()
   { return (::GEOMImpl_IInsertOperations*)GetImpl(); }
 };
index b99e24c226d5cad16d2fd6cd566a36e3f10e85a9..f164b4ef4bb9dc58916730914d297300ac57a73e 100644 (file)
@@ -184,6 +184,69 @@ CORBA::Boolean GEOM_Object_i::GetAutoColor()
 }
 
 
+//=============================================================================
+/*!
+ *  SetMarkerStd
+ */
+//=============================================================================
+void GEOM_Object_i::SetMarkerStd(GEOM::marker_type theType, GEOM::marker_size theSize)
+{
+  if ( theType == GEOM::MT_NONE || theSize == GEOM::MS_NONE ) {
+    _impl->UnsetMarker();
+  }
+  else {
+    Aspect_TypeOfMarker aType = (Aspect_TypeOfMarker)( (int)theType-1 );
+    double aSize = ((int)theSize+1)*0.5;
+    _impl->SetMarkerStd( aType, aSize );
+  }
+}
+
+
+//=============================================================================
+/*!
+ *  SetMarkerTexture
+ */
+//=============================================================================
+void GEOM_Object_i::SetMarkerTexture(CORBA::Long theTextureId)
+{
+  _impl->SetMarkerTexture( theTextureId );
+}
+
+
+//=============================================================================
+/*!
+ *  GetMarkerType
+ */
+//=============================================================================
+GEOM::marker_type GEOM_Object_i::GetMarkerType()
+{
+  return (GEOM::marker_type)( (int)_impl->GetMarkerType()+1 );
+}
+
+
+//=============================================================================
+/*!
+ *  GetMarkerSize
+ */
+//=============================================================================
+GEOM::marker_size GEOM_Object_i::GetMarkerSize()
+{
+  int aSize = (int)( _impl->GetMarkerSize()/0.5 ) - 1;
+  return aSize < GEOM::MS_10 || aSize > GEOM::MS_70 ? GEOM::MS_NONE : (GEOM::marker_size)aSize;
+}
+
+
+//=============================================================================
+/*!
+ *  GetMarkerTexture
+ */
+//=============================================================================
+CORBA::Long GEOM_Object_i::GetMarkerTexture()
+{
+  return _impl->GetMarkerTexture();
+}
+
+
 //=============================================================================
 /*!
  *  SetStudyEntry
index 13bb0290f7646f176e817c497914055a46a4e4e4..b6f16c3546410cac0d2e1917385926f8ec6e1e93 100644 (file)
@@ -62,6 +62,16 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public
 
   virtual CORBA::Boolean GetAutoColor();
 
+  void SetMarkerStd(GEOM::marker_type theType, GEOM::marker_size theSize);
+  
+  void SetMarkerTexture(CORBA::Long theTextureId);
+  
+  GEOM::marker_type GetMarkerType();
+
+  GEOM::marker_size GetMarkerSize();
+
+  CORBA::Long GetMarkerTexture();
+  
   virtual void SetStudyEntry(const char* theEntry);
 
   virtual char* GetStudyEntry();
index 1db9ae08cc0a2a7ad7eaf23efd8c92dc9271d74a..82c1caa7827a4343b1104c9d150435943e4a17a4 100644 (file)
@@ -168,6 +168,84 @@ def ParseSketcherCommand(command):
     Result = Result[:len(Result)-1]
     return Result, StringResult
 
+## Helper function which can be used to pack the passed string to the byte data.
+## Only '1' an '0' symbols are valid for the string. The missing bits are replaced by zeroes.
+## If the string contains invalid symbol (neither '1' not '0'), the function raises an exception.
+## For example,
+## \code
+## val = PackData("10001110") # val = 0xAE
+## val = PackData("1")        # val = 0x80
+## \endcode
+## @ingroup l1_geompy_auxiliary    
+def PackData(data):
+    bytes = len(data)/8
+    if len(data)%8: bytes += 1
+    res = ""
+    for b in range(bytes):
+        d = data[b*8:(b+1)*8]
+        val = 0
+        for i in range(8):
+            val *= 2
+            if i < len(d):
+                if d[i] == "1": val += 1
+                elif d[i] != "0":
+                    raise "Invalid symbol %s" % d[i]
+                pass
+            pass
+        res += chr(val)
+        pass
+    return res
+
+## Read bitmap texture from the text file.
+## In that file, any non-zero symbol represents '1' opaque pixel of the bitmap.
+## A zero symbol ('0') represents transparent pixel of the texture bitmap.
+## The function returns width and height of the pixmap in pixels and byte stream representing
+## texture bitmap itself.
+## 
+## This function can be used to read the texture to the byte stream in order to pass it to
+## the AddTexture() function of geompy class.
+## For example,
+## \code
+## import geompy
+## geompy.init_geom(salome.myStudy)
+## texture = geompy.readtexture('mytexture.dat')
+## texture = geompy.AddTexture(*texture)
+## obj.SetMarkerTexture(texture)
+## \endcode
+## @ingroup l1_geompy_auxiliary    
+def ReadTexture(fname):
+    try:
+        f = open(fname)
+        lines = [ l.strip() for l in f.readlines()]
+        f.close()
+        maxlen = 0
+        if lines: maxlen = max([len(x) for x in lines])
+        lenbytes = maxlen/8
+        if maxlen%8: lenbytes += 1
+        bytedata=""
+        for line in lines:
+            if len(line)%8:
+                lenline = (len(line)/8+1)*8
+                pass
+            else:
+                lenline = (len(line)/8)*8
+                pass
+            for i in range(lenline/8):
+                byte=""
+                for j in range(8):
+                    if i*8+j < len(line) and line[i*8+j] != "0": byte += "1"
+                    else: byte += "0"
+                    pass
+                bytedata += PackData(byte)
+                pass
+            for i in range(lenline/8, lenbytes):
+                bytedata += PackData("0")
+            pass
+        return lenbytes*8, len(lines), bytedata
+    except:
+        pass
+    return 0, 0, ""
+
 ## Kinds of shape enumeration
 #  @ingroup l1_geompy_auxiliary
 kind = GEOM.GEOM_IKindOfShape
@@ -179,7 +257,6 @@ class info:
     CLOSED   = 1
     UNCLOSED = 2
 
-
 class geompyDC(GEOM._objref_GEOM_Gen):
 
         def __init__(self):
@@ -3876,6 +3953,30 @@ class geompyDC(GEOM._objref_GEOM_Gen):
         def addPath(self,Path):
             if (sys.path.count(Path) < 1):
                 sys.path.append(Path)
+                pass
+            pass
+
+        ## Load marker texture from the file
+        #  @ingroup l1_geompy_auxiliary
+        def LoadTexture(self, Path):
+            # Example: see GEOM_TestAll.py
+            ID = self.InsertOp.LoadTexture(Path)
+            RaiseIfFailed("LoadTexture", self.InsertOp)
+            return ID
+
+        ## Add marker texture. \a Width and \a Height parameters
+        #  specify width and height of the texture in pixels.
+        #  If \a RowData is True, \a Texture parameter should represent texture data
+        #  packed into the byte array. If \a RowData is False (default), \a Texture
+        #  parameter should be unpacked string, in which '1' symbols represent opaque
+        #  pixels and '0' represent transparent pixels of the texture bitmap.
+        #  @ingroup l1_geompy_auxiliary
+        def AddTexture(self, Width, Height, Texture, RowData=False):
+            # Example: see GEOM_TestAll.py
+            if not RowData: Texture = PackData(Texture)
+            ID = self.InsertOp.AddTexture(Width, Height, Texture)
+            RaiseIfFailed("AddTexture", self.InsertOp)
+            return ID
 
 import omniORB
 #Register the new proxy for GEOM_Gen