MantisBT - Community
View Issue Details
0031324Community[OCCT] OCCT:Data Exchangepublic2020-01-28 15:082020-07-31 11:42
BenjaminBihler 
gka 
normalminor 
resolvedopen 
MinGw64Windows7
[OCCT] 7.5.0* 
[OCCT] 7.5.0* 
0031324: [Regression to OCCT 7.4.0] Data Exchange - Cannot read BinOcaf document with colour
It seems as if an error has been introduced with commit aaf8d6a98d5aa23513bbb7f0e8528764e1e0ebb4.

I create a simple BinOcaf document containing a vertex and a presentation with white color using OCCT 7.4.0. This document cannot be read in after the commit named above.

A Standard_OutOfRange failure is thrown in Quantity_Color::valuesOf(...), since a color with the value 516 is passed to that method, but the highest possible Quantity_NameOfColor value is 508 (Quantity_NOC_WHITE).
Making document:
pload MODELING VISUALIZATION OCAF
NewDocument D BinOcaf
#NewDocument D XmlOcaf
box b1 0 0 0 1 1 1
box b2 2 0 0 1 1 1
box b3 4 0 0 1 1 1
set aLab1 [ImportShape D 0:2 b1 Box1]
set aLab2 [ImportShape D 0:3 b2 Box2]
set aLab3 [ImportShape D 0:4 b3 Box3]
AISInitViewer D
vsetdispmode 1
AISSet D $aLab1 NS
AISSet D $aLab2 NS
AISSet D $aLab3 NS
AISDisplay D $aLab1
AISDisplay D $aLab2
AISDisplay D $aLab3
vfit
AISColor D $aLab1 22;  # old blue
AISColor D $aLab2 412; # old red
AISColor D $aLab3 516; # old white
#AISColor D $aLab1 BLUE
#AISColor D $aLab2 RED
#AISColor D $aLab3 WHITE
SaveAs D doc.cbf
#SaveAs D doc.xml


Reading document:
pload MODELING VISUALIZATION OCAF
catch { Close D }
Open doc.cbf D
AISInitViewer D
vsetdispmode 1
vfit
vreadpixel 100 150 -rgb -name; # BLUE3
vreadpixel 200 200 -rgb -name; # RED3
vreadpixel 300 300 -rgb -name; # LIGHTGRAY


Please adjust the setting of CSF_StandardDefaults and CSF_PluginDefaults.

Document creation program (OCCT before commit aaf8d6a98d5aa23513bbb7f0e8528764e1e0ebb4):

#include <TDocStd_Document.hxx>
#include <AppStd_Application.hxx>
#include <TDataStd_Name.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_Viewer.hxx>
#include <TPrsStd_AISViewer.hxx>
#include <TDataStd_Name.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <TPrsStd_AISPresentation.hxx>

int main(int, char**)
{
#if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) || \
  defined(__MINGW64__))
  _putenv("CSF_StandardDefaults=C:/Libraries/OpenCascade/occt/src/StdResource");
  _putenv("CSF_PluginDefaults=C:/Libraries/OpenCascade/occt/src/StdResource");
#else
  setenv("CSF_StandardDefaults", resourceDirectory.c_str(), 1);
  setenv("CSF_PluginDefaults", resourceDirectory.c_str(), 1);
#endif

  Handle(TDocStd_Application) app = new AppStd_Application;
  Handle(TDocStd_Document) doc;
  app->NewDocument("BinOcaf", doc);

      Handle(Aspect_DisplayConnection) displayConnection;

  #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || \
          defined(MACOSX_USE_GLX))

      displayConnection = new Aspect_DisplayConnection(getenv("DISPLAY"));
  #endif

      Handle(OpenGl_GraphicDriver) graphicDriver = new OpenGl_GraphicDriver(displayConnection);

      Handle(V3d_Viewer) viewer = new V3d_Viewer(
              graphicDriver);

      viewer->SetDefaultLights();
      viewer->SetLightOn();

      TDF_Label root = doc->Main().Root();

      Handle(TPrsStd_AISViewer) viewerAttribute;

      // Create AisViewer instance
      if (!TPrsStd_AISViewer::Find(root, viewerAttribute))
      {
          viewerAttribute = TPrsStd_AISViewer::New(root, viewer);
      }

    TDF_Label label = doc->Main().NewChild();

      Handle(TDataStd_Name) nameAttribute = TDataStd_Name::Set(label,
              TCollection_ExtendedString("Test"));

      TNaming_Builder builder(label);

      TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(gp_Pnt());
      builder.Generated(vertex);

      Handle(TPrsStd_AISPresentation) presentation = TPrsStd_AISPresentation::Set(
              label, TNaming_NamedShape::GetID());

             presentation->SetColor(Quantity_NOC_WHITE);

      // Set surface appearance to colored plastic to prevent excessive shine
      presentation->SetMaterial(Graphic3d_NameOfMaterial::Graphic3d_NOM_PLASTIC);

      presentation->SetMode(AIS_Shaded);
      presentation->Display(Standard_True);

// TPrsStd_AISViewer::Update(label);

    PCDM_StoreStatus status = app->SaveAs(doc, TCollection_ExtendedString(
            "Example.cbf"));

  std::cout << "Status: " << status << std::endl;

  if( status != PCDM_SS_OK)
  {
      std::cerr << "Store error!" << std::endl;
  }
  else
  {
      std::cout << "Document is stored." << std::endl;
  }
}







Document reading program (fails from commit aaf8d6a98d5aa23513bbb7f0e8528764e1e0ebb4 on):

#include <TDocStd_Document.hxx>
#include <AppStd_Application.hxx>
#include <TDataStd_Name.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_Viewer.hxx>
#include <TPrsStd_AISViewer.hxx>

int main(int, char**)
{
#if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) || \
  defined(__MINGW64__))
    _putenv("CSF_StandardDefaults=C:/Libraries/OpenCascade/occt/src/StdResource");
    _putenv("CSF_PluginDefaults=C:/Libraries/OpenCascade/occt/src/StdResource");
#else
    setenv("CSF_StandardDefaults", resourceDirectory.c_str(), 1);
    setenv("CSF_PluginDefaults", resourceDirectory.c_str(), 1);
#endif

    Handle(TDocStd_Application) app = new AppStd_Application;
    Handle(TDocStd_Document) doc;
    app->Open(TCollection_ExtendedString("Example.cbf"), doc);

    Handle(Aspect_DisplayConnection) displayConnection;

#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || \
        defined(MACOSX_USE_GLX))

    displayConnection = new Aspect_DisplayConnection(getenv("DISPLAY"));
#endif

    Handle(OpenGl_GraphicDriver) graphicDriver = new OpenGl_GraphicDriver(displayConnection);

    Handle(V3d_Viewer) viewer = new V3d_Viewer(
            graphicDriver);

    viewer->SetDefaultLights();
    viewer->SetLightOn();

    TDF_Label root = doc->Main().Root();

    Handle(TPrsStd_AISViewer) viewerAttribute;

    // Create AisViewer instance
    if (!TPrsStd_AISViewer::Find(root, viewerAttribute))
    {
        viewerAttribute = TPrsStd_AISViewer::New(root, viewer);
    }
}
No tags attached.
related to 0030969verified apn Open CASCADE Coding Rules - refactor Quantity_Color.cxx color table definition 
related to 0027974closed apn Open CASCADE Visualization, ray tracing - Improve ray tracing engine 
? doc_740.cbf (16,993) 2020-01-29 11:55
https://tracker.dev.opencascade.org/
xml doc_740.xml (13,896) 2020-01-29 13:16
https://tracker.dev.opencascade.org/
Issue History
2020-01-28 15:08BenjaminBihlerNew Issue
2020-01-28 15:08BenjaminBihlerAssigned To => gka
2020-01-28 15:08BenjaminBihlerRelationship addedrelated to 0030969
2020-01-29 11:54kgvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22481#r22481
2020-01-29 11:55kgvFile Added: doc_740.cbf
2020-01-29 13:16kgvFile Added: doc_740.xml
2020-01-29 14:42gitNote Added: 0090139
2020-01-29 14:48kgvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22484#r22484
2020-01-29 14:52kgvRelationship addedrelated to 0027974
2020-01-29 16:09kgvNote Added: 0090149
2020-01-29 16:09kgvStatusnew => resolved
2020-06-03 11:33gkaNote Added: 0092455
2020-06-03 11:33gkaAssigned Togka => bugmaster
2020-06-03 11:33gkaStatusresolved => reviewed
2020-06-04 10:32kgvNote Added: 0092472
2020-06-04 10:32kgvAssigned Tobugmaster => kgv
2020-06-04 10:32kgvStatusreviewed => assigned
2020-07-30 23:39gitNote Added: 0093409
2020-07-31 11:42kgvNote Added: 0093411
2020-07-31 11:42kgvAssigned Tokgv => gka
2020-07-31 11:42kgvStatusassigned => resolved

Notes
(0090139)
git   
2020-01-29 14:42   
Branch CR31324 has been created by kgv.

SHA-1: 29631ac7eac8c4c22174ba720d37268a2dac014a


Detailed log of new commits:

Author: kgv
Date: Wed Jan 29 13:18:01 2020 +0300

    0031324: Data Exchange - Cannot read BinOcaf document with colour
    
    BinMDataXtd_PresentationDriver and XmlMDataXtd_PresentationDriver have been corrected
    to convert old (OCCT 7.4.0) Quantity_NameOfColor enumeration values to new ones.
    The writers have been modified to avoid storing color as enumeration index.
    
    TPrsStd package has been marked deprecated.
(0090149)
kgv   
2020-01-29 16:09   
Patch is ready for review.
(0092455)
gka   
2020-06-03 11:33   
Branches CR21324 were reviewed
(0092472)
kgv   
2020-06-04 10:32   
As has been discussed with Andrey, it is proposed to revert changes in persistence format within the patch.
(0093409)
git   
2020-07-30 23:39   
Branch CR31324_1 has been created by kgv.

SHA-1: b91ed98ebdf75d0e493ec71cfddc111799043e72


Detailed log of new commits:

Author: kgv
Date: Wed Jan 29 13:18:01 2020 +0300

    0031324: Data Exchange - Cannot read BinOcaf document with colour
    
    BinMDataXtd_PresentationDriver and XmlMDataXtd_PresentationDriver have been corrected
    to convert old (OCCT 7.4.0) Quantity_NameOfColor enumeration values to new ones.
(0093411)
kgv   
2020-07-31 11:42   
Updated patch is ready for review in OCCT branch CR31324_1.

http://jenkins-test-12.nnov.opencascade.com:8080/view/CR31324_1-master-KGV [^]