From: vsr Date: Tue, 3 Nov 2009 10:48:50 +0000 (+0000) Subject: Issue 0020012: EDF 831 GEOM : API for points representation in 3D viewer X-Git-Tag: V5_1_3rc2~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=282891ef18d791cfee6524a5ce463d9e499ebf23;p=modules%2Fgeom.git Issue 0020012: EDF 831 GEOM : API for points representation in 3D viewer --- diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index f239246ad..96eed9a93 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -42,6 +42,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include @@ -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& 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& 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 GEOM_Engine::getAllTextures(int theDocID) +{ + std::list 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< allTextures = engine->getAllTextures(theDocID); + std::list::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"; } } diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index c901123b6..6ec146c92 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -37,6 +37,8 @@ #include #include +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 getAllTextures(int theDocID); + + static const Standard_GUID& GetTextureGUID(); + protected: Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine); diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index b2ca175f4..38025ab06 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -33,11 +33,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -45,11 +47,16 @@ #include #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 diff --git a/src/GEOM/GEOM_Object.hxx b/src/GEOM/GEOM_Object.hxx index dd2f73ea2..66f93f642 100644 --- a/src/GEOM/GEOM_Object.hxx +++ b/src/GEOM/GEOM_Object.hxx @@ -55,6 +55,9 @@ #ifndef _TCollection_AsciiString_HeaderFile #include #endif +#ifndef _Aspect_TypeOfMarker_HeaderFile +#include +#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); diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 61b86c34c..435419768 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -79,6 +79,7 @@ #include #include #include +#include // VTK Includes #include @@ -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 ); + } + } } } } diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 81efb22a1..cfb50c82b 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -80,6 +80,7 @@ #include #include #include +#include #include @@ -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(); diff --git a/src/GEOMGUI/GeometryGUI.h b/src/GEOMGUI/GeometryGUI.h index a82efcb25..67a793b7e 100644 --- a/src/GEOMGUI/GeometryGUI.h +++ b/src/GEOMGUI/GeometryGUI.h @@ -41,6 +41,7 @@ // OCCT Includes #include +#include // 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 TextureMap; + typedef QMap 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 myRules; // popup rules + static StudyTextureMap myTextureMap; // texture map QList myOCCSelectors; QList myVTKSelectors; @@ -174,7 +184,7 @@ private: LightApp_Displayer* myDisplayer; int myLocalSelectionMode; //Select Only -friend class DisplayGUI; + friend class DisplayGUI; }; #endif diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index 884c457cf..80f4a2962 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -48,6 +48,7 @@ #include #include #include +#include #include #include // 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 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 bytedata; + std::list::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::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 GEOMImpl_IInsertOperations::GetAllTextures() +{ + SetErrorCode(KO); + std::list id_list = GetEngine()->getAllTextures(GetDocID()); + SetErrorCode(OK); + return id_list; +} diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx index aba0c227f..51d2ed350 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx @@ -30,6 +30,9 @@ #include #include #include +#include + +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 GetAllTextures(); + private: Standard_Boolean InitResMgr (); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index bc7e8fd23..ea3251f19 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -70,6 +70,7 @@ #include #include #include +#include // QT Includes #include @@ -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 ); diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.cc b/src/GEOM_I/GEOM_IInsertOperations_i.cc index b32b3eb71..c5570650e 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.cc +++ b/src/GEOM_I/GEOM_IInsertOperations_i.cc @@ -35,6 +35,7 @@ #include "GEOM_Object.hxx" #include +#include //============================================================================= /*! @@ -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 localIDs = GetOperations()->GetAllTextures(); + GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size()); + anIDs->length(localIDs.size()); + std::list::const_iterator anIt; + int i = 0; + for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++) + anIDs[i] = *anIt; + return anIDs._retn(); +} diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.hh b/src/GEOM_I/GEOM_IInsertOperations_i.hh index da29eabf0..49a426981 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.hh +++ b/src/GEOM_I/GEOM_IInsertOperations_i.hh @@ -27,6 +27,7 @@ #include #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(); } }; diff --git a/src/GEOM_I/GEOM_Object_i.cc b/src/GEOM_I/GEOM_Object_i.cc index b99e24c22..f164b4ef4 100644 --- a/src/GEOM_I/GEOM_Object_i.cc +++ b/src/GEOM_I/GEOM_Object_i.cc @@ -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 diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index 13bb0290f..b6f16c354 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -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(); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 1db9ae08c..82c1caa78 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -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