0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IGESCAFControl / IGESCAFControl_Writer.cxx
index ee2c7ce..fdca8f6 100644 (file)
@@ -13,7 +13,6 @@
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-
 #include <IGESCAFControl.hxx>
 #include <IGESCAFControl_Writer.hxx>
 #include <IGESData_IGESEntity.hxx>
 #include <IGESGraph_Color.hxx>
 #include <IGESGraph_DefinitionLevel.hxx>
 #include <IGESSolid_Face.hxx>
+#include <IGESBasic_Name.hxx>
 #include <NCollection_DataMap.hxx>
 #include <Standard_Transient.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
+#include <TCollection_HExtendedString.hxx>
 #include <TColStd_HSequenceOfExtendedString.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDF_ChildIterator.hxx>
@@ -151,31 +152,19 @@ Standard_Boolean IGESCAFControl_Writer::Transfer (const Handle(TDocStd_Document)
   STool->GetFreeShapes ( labels );
   return Transfer (labels);
 }  
-  
-//=======================================================================
-//function : Perform
-//purpose  : 
-//=======================================================================
 
-Standard_Boolean IGESCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
-                                                const Standard_CString filename)
-{
-  if ( ! Transfer ( doc ) ) return Standard_False;
-  return Write ( filename ) == IFSelect_RetDone;
-}
-  
 //=======================================================================
-//function : Perform
+//function : Transfer
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean IGESCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
-                                                const TCollection_AsciiString &filename)
+Standard_Boolean IGESCAFControl_Writer::Transfer (const TDF_Label& label)
 {
-  if ( ! Transfer ( doc ) ) return Standard_False;
-  return Write ( filename.ToCString() ) == IFSelect_RetDone;
+  TDF_LabelSequence labels;
+  labels.Append( label );
+  return Transfer( labels );
 }
-  
+
 //=======================================================================
 //function : Transfer
 //purpose  : 
@@ -210,6 +199,30 @@ Standard_Boolean IGESCAFControl_Writer::Transfer (const TDF_LabelSequence& label
   return Standard_True;
 }
 
+//=======================================================================
+//function : Perform
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean IGESCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
+                                                const Standard_CString filename)
+{
+  if ( ! Transfer ( doc ) ) return Standard_False;
+  return Write ( filename ) == IFSelect_RetDone;
+}
+  
+//=======================================================================
+//function : Perform
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean IGESCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
+                                                const TCollection_AsciiString &filename)
+{
+  if ( ! Transfer ( doc ) ) return Standard_False;
+  return Write ( filename.ToCString() ) == IFSelect_RetDone;
+}
+  
 //=======================================================================
 //function : WriteAttributes
 //purpose  : 
@@ -223,7 +236,7 @@ Standard_Boolean IGESCAFControl_Writer::WriteAttributes (const TDF_LabelSequence
     TDF_Label L = labels.Value(i);
 
     // collect color settings
-    XCAFPrs_DataMapOfShapeStyle settings;
+    XCAFPrs_IndexedDataMapOfShapeStyle settings;
     TopLoc_Location loc;
     XCAFPrs::CollectStyleSettings ( L, loc, settings );
     if ( settings.Extent() <=0 ) continue;
@@ -249,7 +262,7 @@ Standard_Boolean IGESCAFControl_Writer::WriteAttributes (const TDF_LabelSequence
 //=======================================================================
 
 void IGESCAFControl_Writer::MakeColors (const TopoDS_Shape &S, 
-                                       const XCAFPrs_DataMapOfShapeStyle &settings,
+                                       const XCAFPrs_IndexedDataMapOfShapeStyle &settings,
                                        XCAFPrs_DataMapOfStyleTransient &colors,
                                        TopTools_MapOfShape &Map,
                                        const XCAFPrs_Style &inherit) 
@@ -259,10 +272,11 @@ void IGESCAFControl_Writer::MakeColors (const TopoDS_Shape &S,
   
   // check if shape has its own style (or inherits from ancestor)
   XCAFPrs_Style style = inherit;
-  if ( settings.IsBound(S) ) {
-    XCAFPrs_Style own = settings.Find(S);
+  if ( settings.Contains(S) ) {
+    XCAFPrs_Style own = settings.FindFromKey(S);
     if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
     if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
+    style.SetMaterial (own.Material());
   }
   
   // analyze whether current entity should get a color 
@@ -273,6 +287,12 @@ void IGESCAFControl_Writer::MakeColors (const TopoDS_Shape &S,
       hasColor = Standard_True;
       col = style.GetColorSurf();
     }
+    else if (!style.Material().IsNull()
+          && !style.Material()->IsEmpty())
+    {
+      hasColor = Standard_True;
+      col = style.Material()->BaseColor().GetRGB();
+    }
   }
   else if ( S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE ) {
     if ( style.IsSetColorCurv() ) {
@@ -295,7 +315,9 @@ void IGESCAFControl_Writer::MakeColors (const TopoDS_Shape &S,
        Handle(TCollection_HAsciiString) str = 
          new TCollection_HAsciiString ( col.StringName ( col.Name() ) );
        colent = new IGESGraph_Color;
-       colent->Init ( col.Red() * 100., col.Green() * 100., col.Blue() * 100., str );
+       NCollection_Vec3<Standard_Real> aColor_sRGB;
+       col.Values (aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b(), Quantity_TOC_sRGB);
+       colent->Init ( aColor_sRGB.r() * 100., aColor_sRGB.g() * 100., aColor_sRGB.b() * 100., str );
        AddEntity ( colent );
        colors.Bind ( c, colent );
       }
@@ -391,7 +413,7 @@ static void AttachLayer (const Handle(Transfer_FinderProcess) &FP,
       Igesent->InitLevel( 0, localIntName );
     }
 #ifdef OCCT_DEBUG
-    else cout << "Warning: Can't find entity for shape in mapper" << endl;
+    else std::cout << "Warning: Can't find entity for shape in mapper" << std::endl;
 #endif
   }
 }
@@ -515,6 +537,14 @@ Standard_Boolean IGESCAFControl_Writer::WriteNames (const TDF_LabelSequence& the
         anAsciiName->SetValue (aNameLength+1, IsAnAscii (aName.Value (aCharPos)) ? (Standard_Character )aName.Value (aCharPos) : '?');
       }
       anIGESEntity->SetLabel (anAsciiName);
+
+      // Set long IGES name using 406 form 15 entity
+      Handle(IGESBasic_Name) aLongNameEntity = new IGESBasic_Name;
+      Handle(TCollection_HExtendedString) aTmpStr = new TCollection_HExtendedString(aName);
+      aLongNameEntity->Init(1, new TCollection_HAsciiString(aTmpStr, '_'));
+
+      anIGESEntity->AddProperty(aLongNameEntity);
+      AddEntity(aLongNameEntity);
     }
   }