Esempio n. 1
0
ON_BOOL32 ON_ClippingPlaneSurface::Write( ON_BinaryArchive& file ) const
{
  bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (!rc)
    return false;

  for(;;)
  {
    rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,0);
    if (rc)
    {
      rc = ON_PlaneSurface::Write(file)?true:false;
      if (!file.EndWrite3dmChunk())
        rc = false;
    }
    if (!rc) break;

    rc = m_clipping_plane.Write(file);
    if (rc) break;

    break;
  }

  if (!file.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 2
0
ON_BOOL32 ON_SurfaceArray::Write( ON_BinaryArchive& file ) const
{
  ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
  if (rc) rc = file.Write3dmChunkVersion(1,0);
  if (rc ) 
  {
    int i;
    rc = file.WriteInt( Count() );
    for ( i = 0; rc && i < Count(); i++ ) {
      if ( m_a[i] ) 
      {
        rc = file.WriteInt(1);
        if ( rc ) 
          rc = file.WriteObject( *m_a[i] ); // polymorphic surfaces
      }
      else 
      {
        // NULL surface
        rc = file.WriteInt(0);
      }
    }
    if ( !file.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
Esempio n. 3
0
BOOL ON_UserStringList::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if ( !rc )
    return false;

  for(;;)
  {
    int count = m_e.Count();
    rc = archive.WriteInt(count);
    if(!rc) break;

    for ( int i = 0; i < count && rc; i++ )
    {
      rc = m_e[i].Write(archive);
    }
    if (!rc) break;

    break;
  }

  if ( !archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
ON_BOOL32 ON_PolyEdgeSegment::Write( ON_BinaryArchive& archive ) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (!rc)
    return false;
  for(;;)
  {
    rc = archive.WriteUuid(m_object_id);
    if (!rc) break;
    rc = archive.WriteComponentIndex(m_component_index);
    if (!rc) break;
    rc = archive.WriteInterval(m_edge_domain);
    if (!rc) break;
    rc = archive.WriteInterval(m_trim_domain);
    if (!rc) break;
    bool b = ON_CurveProxy::ProxyCurveIsReversed();
    rc = archive.WriteBool(b);
    if (!rc) break;
    rc = archive.WriteInterval(ON_CurveProxy::Domain());
    if (!rc) break;
    rc = archive.WriteInterval(ON_CurveProxy::ProxyCurveDomain());
    if (!rc) break;

    break;
  }
  if ( !archive.EndWrite3dmChunk() )
    rc = false;
  return rc;
}
Esempio n. 5
0
BOOL ON_BrepFaceArray::Write( ON_BinaryArchive& file ) const
{
  int i;
  BOOL rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
  if (rc)
  {
    rc = file.Write3dmChunkVersion(1,1); // 1.1 added m_face_uuid

    // chunk version 1.0 and later
    const int count = Count();
    if (rc) rc = file.WriteInt( count );
    for ( i = 0; rc && i < count; i++ )
    {
      if (rc) rc = m_a[i].Write(file);
    }

    // chunk version 1.1 and later
    for ( i = 0; rc && i < count; i++ )
    {
      rc = file.WriteUuid( m_a[i].m_face_uuid );
    }

    if ( !file.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
Esempio n. 6
0
bool ON_ClippingPlaneInfo::Write( ON_BinaryArchive& file ) const
{
  bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (!rc)
    return false;
  
  for(;;)
  {
    rc = file.WritePlaneEquation(m_plane_equation);
    if (!rc) break;

    rc = file.WriteUuid(m_plane_id);
    if (!rc) break;

    rc = file.WriteBool(m_bEnabled);
    if (!rc) break;

    break;
  }

  if ( !file.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 7
0
// virtual ON_Object override
ON_BOOL32 ON__IDefLayerSettingsUserData::Write(ON_BinaryArchive& binary_archive) const
{
  bool rc = binary_archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
  if ( !rc )
    return false;

  rc = false;
  for(;;)
  {
    if ( !binary_archive.WriteArray(m_layers.Count(),m_layers.Array()) )
      break;

    // added in version 1.1 chunks
    bool bHaveParentLayer = ( 0 != m_idef_layer_table_parent_layer );
    if ( !binary_archive.WriteBool(bHaveParentLayer) )
      break;

    if ( bHaveParentLayer )
    {
      if ( !binary_archive.WriteObject(m_idef_layer_table_parent_layer) )
        break;
    }

    rc = true;
    break;
  }

  if ( !binary_archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 8
0
ON_BOOL32 ON_Linetype::Write( ON_BinaryArchive& file) const
{
  bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
  if (rc)
  {
    for(;;)
    {
      // chunk version 1.0 fields
      rc = file.WriteInt( LinetypeIndex());
      if(!rc) break;

      rc = file.WriteString( m_linetype_name );
      if (!rc) break;

      rc = file.WriteArray( m_segments );
      if(!rc) break;

      // chunk version 1.1 fields
      rc = file.WriteUuid( m_linetype_id );
      if (!rc) break;

      break;
    }

    if ( !file.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
Esempio n. 9
0
bool ON_PlugInRef::Write( ON_BinaryArchive& file ) const
{
  bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,2);
  if (rc)
  {
    //version 1.0 fields
    if (rc) rc = file.WriteUuid(m_plugin_id);
    if (rc) rc = file.WriteInt(m_plugin_type);
    if (rc) rc = file.WriteString(m_plugin_name);
    if (rc) rc = file.WriteString(m_plugin_version);
    if (rc) rc = file.WriteString(m_plugin_filename);

    // version 1.1 fields 
    if (rc) rc = file.WriteString(m_developer_organization);
    if (rc) rc = file.WriteString(m_developer_address);
    if (rc) rc = file.WriteString(m_developer_country);
    if (rc) rc = file.WriteString(m_developer_phone);
    if (rc) rc = file.WriteString(m_developer_email);
    if (rc) rc = file.WriteString(m_developer_website);
    if (rc) rc = file.WriteString(m_developer_updateurl);
    if (rc) rc = file.WriteString(m_developer_fax);

    // version 1.2 fields
    if (rc) rc = file.WriteInt(m_plugin_platform);
    if (rc) rc = file.WriteInt(m_plugin_sdk_version);
    if (rc) rc = file.WriteInt(m_plugin_sdk_service_release);

    if( !file.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
Esempio n. 10
0
ON_BOOL32 ON_DetailView::Write( ON_BinaryArchive& archive ) const
{
  bool rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 1 );
  if (!rc)
    return false;

  for(;;)
  {
    // m_view is wrapped in a subchunk so ON_3dmView can be expanded 
    // without breaking the file format.
    rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
    if (rc) 
    {
      rc = m_view.Write(archive);
      if (!archive.EndWrite3dmChunk())
        rc = false;
    }
    if(!rc)
      break;

    // m_boundary is wrapped in a subchunk so ON_NurbsCurve can be expanded 
    // without breaking the file format.
    rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
    if (rc) 
    {
      rc = m_boundary.Write(archive)?true:false;
      if (!archive.EndWrite3dmChunk())
        rc = false;
    }
    if(!rc)
      break;

    // 28 Feb 2006  1.1 fields added
    rc = archive.WriteDouble(m_page_per_model_ratio);
    if ( !rc )
      break;

    break;
  }

  if ( !archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 11
0
bool ON_Localizer::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (!rc)
    return false;

  for(;;)
  {
    rc = archive.WriteInt(m_type);
    if ( !rc ) break;
    rc = archive.WritePoint(m_P);
    if ( !rc ) break;
    rc = archive.WriteVector(m_V);
    if ( !rc ) break;
    rc = archive.WriteInterval(m_d);
    if ( !rc ) break;

    rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
    if (!rc) break;
    rc = archive.WriteBool( m_nurbs_curve ? true : false );
    if ( rc && m_nurbs_curve )
      rc = m_nurbs_curve->Write(archive)?true:false;
    if ( !archive.EndWrite3dmChunk() )
      rc = false;
    if (!rc) break;

    rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
    if (!rc) break;
    rc = archive.WriteBool( m_nurbs_surface ? true : false );
    if ( rc && m_nurbs_surface )
      rc = m_nurbs_surface->Write(archive)?true:false;
    if ( !archive.EndWrite3dmChunk() )
      rc = false;
    if (!rc) break;

    break;
  }
  
  if ( !archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 12
0
ON_BOOL32 ON_HatchExtra::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);

  if(rc) rc = archive.WriteUuid( m_parent_hatch);
  if(rc) rc = archive.WritePoint(m_basepoint);

  if(!archive.EndWrite3dmChunk())
    rc = false;

  return rc;
}
bool ON_BezierCage::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);

  if (rc)
  {
    rc = archive.WriteInt(m_dim);
    if(rc)
      rc = archive.WriteInt(m_is_rat);
    if (rc)
      rc = archive.WriteInt(m_order[0]);
    if (rc)
      rc = archive.WriteInt(m_order[1]);
    if (rc)
      rc = archive.WriteInt(m_order[2]);
    int i,j,k;
    const int cv_dim = m_is_rat?(m_dim+1):m_dim;
    double* bogus_cv = 0;
    for(i = 0; i < m_order[0] && rc; i++)
    {
      for(j = 0; j < m_order[1] && rc; j++)
      {
        for ( k = 0; k < m_order[2] && rc; k++)
        {
          const double* cv = CV(i,j,k);
          if ( !cv )
          {
            if ( 0 == bogus_cv )
            {
              bogus_cv = (double*)onmalloc(cv_dim*sizeof(*bogus_cv));
              for ( int n = 0; n < cv_dim; n++ )
                bogus_cv[n] = ON_UNSET_VALUE;
            }
            cv = bogus_cv;
          }
          rc = archive.WriteDouble(cv_dim,cv);
        }
      }
    }

    if ( 0 != bogus_cv )
      onfree(bogus_cv);

    if ( !archive.EndWrite3dmChunk() )
    {
      rc = false;
    }
  }

  return rc;
}
bool ON_BezierCageMorph::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (rc)
  {
    if (rc)
      rc = archive.WriteXform(m_xyz2rst);
    if(rc)
      rc = m_rst2xyz.Write(archive);
    if ( !archive.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
BOOL CSampleObjectUserData::Write( ON_BinaryArchive& binary_archive ) const
{
  int minor_version = 0;
  bool rc = binary_archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, minor_version );
  if( !rc )
    return false;

  // Write class members like this
  for(;;)
  {
    // version 1.0 fields
    rc = binary_archive.WritePoint( m_point );
    if( !rc ) break;

    rc = binary_archive.WriteString( m_string );
    if( !rc ) break;

    // If you add data members to CSampleObjectUserData after you 
    // have released a product, simply increment minor_version
    // by one, and write the new information.  This way you
    // can enhance your user data over several versions of
    // your product without breaking file IO.  It is CRITICAL
    // that once you write something to a customer's .3dm
    // file, you continue to write it the same way for all
    // future versions.
    
    // version 1.1 fields added DD MMM YYYY
    // rc = binary_archive.WriteSomethingNew( ... );
    // if (!rc) break;
    // rc = binary_archive.WriteSomethingElseNew( ... );
    // if (!rc) break;
    
    // version 1.2 fields added DD MMM YYYY
    // rc = binary_archive.WriteAnotherSomethingNew( ... );
    // if (!rc) break;
    // rc = binary_archive.WriteAnotherSomethingElseNew( ... );
    // if (!rc) break;

    break;
  }

  // If BeginWrite3dmChunk() returns true,
  // then EndWrite3dmChunk() must be called, 
  // even if a write operation failed.
  if( !binary_archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 16
0
BOOL ON_BrepLoopArray::Write( ON_BinaryArchive& file ) const
{
  int i;
  BOOL rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
  if (rc) {
    rc = file.Write3dmChunkVersion(1,0);
    const int count = Count();
    if (rc) rc = file.WriteInt( count );
    for ( i = 0; rc && i < count; i++ ) {
      if (rc) rc = m_a[i].Write(file);
    }
    if ( !file.EndWrite3dmChunk() )
      rc = false;
  }
  return rc;
}
bool ON_BrepRegionArray::Write( ON_BinaryArchive& file ) const
{
    int i;
    bool rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
    if (rc)
    {
        const int count = Count();
        if (rc) rc = file.WriteInt( count );
        for ( i = 0; rc && i < count; i++ )
        {
            rc = m_a[i].Write(file)?true:false;
        }
        if ( !file.EndWrite3dmChunk() )
            rc = false;
    }
    return rc;
}
bool ON_BrepRegionTopology::Write( ON_BinaryArchive& file) const
{
    bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
    if (!rc)
        return false;
    for(;;)
    {
        rc = m_FS.Write(file);
        if (!rc) break;
        rc = m_R.Write(file);
        if (!rc) break;

        break;
    }
    if ( !file.EndWrite3dmChunk() )
        rc = false;
    return rc;
}
Esempio n. 19
0
ON_BOOL32 ON_MeshNgonUserData::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
  if (!rc)
    return false;
  for (;;)
  {
    int count = ( 0 == m_ngon_list ) ? 0 : m_ngon_list->NgonCount();
    const ON_MeshNgon* ngon_array = (count > 0) ? m_ngon_list->Ngon(0) : 0;
    if ( 0 == ngon_array )
      count = 0;
    rc = archive.WriteInt(count);
    if (count <= 0 || !rc)
      break;
    for ( int i = 0; i < count; i++ )
    {
      const struct ON_MeshNgon& ngon = ngon_array[i];
      rc = archive.WriteInt(ngon.N);
      if (!rc)
        break;
      rc = archive.WriteInt(ngon.N,ngon.vi);
      if (!rc)
        break;
      rc = archive.WriteInt(ngon.N,ngon.fi);
      if (!rc)
        break;
    }
    if (!rc)
      break;

    // chunk version 1.1 added face and vertex validation counts.
    rc = archive.WriteInt(m_mesh_F_count);
    if (!rc)
      break;
    rc = archive.WriteInt(m_mesh_V_count);
    if (!rc)
      break;

    break;
  }
  if ( !archive.EndWrite3dmChunk() )
    rc = false;
  return rc;
}
Esempio n. 20
0
bool ON_UserString::Write(ON_BinaryArchive& archive) const
{
  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if (!rc)
    return false;

  for(;;)
  {
    rc = archive.WriteString(m_key);
    if (!rc) break;
    rc = archive.WriteString(m_string_value);
    if (!rc) break;

    break;
  }

  if ( !archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 21
0
bool ON_CompressedBuffer::Write( ON_BinaryArchive& binary_archive ) const
{
  bool rc = binary_archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if ( !rc )
    return false;

  for(;;)
  {
    rc = binary_archive.WriteSize(m_sizeof_uncompressed);
    if (!rc)
      break;
    rc = binary_archive.WriteSize((m_buffer_compressed && m_sizeof_compressed>0) ? m_sizeof_compressed : 0);
    if (!rc)
      break;
    rc = binary_archive.WriteInt(m_crc_uncompressed);
    if (!rc)
      break;
    rc = binary_archive.WriteInt(m_crc_compressed);
    if (!rc)
      break;
    rc = binary_archive.WriteInt(m_method);
    if (!rc)
      break;
    rc = binary_archive.WriteInt(m_sizeof_element);
    if (!rc)
      break;
    if ( m_buffer_compressed && m_sizeof_compressed > 0 )
    {
      rc = binary_archive.WriteByte(m_sizeof_compressed,m_buffer_compressed);
      if (!rc)
        break;
    }
    break;
  }

  if ( !binary_archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
ON_BOOL32 ON_BrepFaceSide::Write(ON_BinaryArchive& file) const
{
    bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
    if ( !rc )
        return false;
    for(;;)
    {
        rc = file.WriteInt( m_faceside_index );
        if (!rc) break;
        rc = file.WriteInt( m_ri );
        if (!rc) break;
        rc = file.WriteInt( m_fi );
        if (!rc) break;
        rc = file.WriteInt( m_srf_dir );
        if (!rc) break;

        break;
    }
    if (!file.EndWrite3dmChunk())
        rc = false;
    return rc;
}
ON_BOOL32 ON_BrepRegion::Write(ON_BinaryArchive& file) const
{
    bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
    if ( !rc )
        return false;
    for(;;)
    {
        rc = file.WriteInt( m_region_index );
        if (!rc) break;
        rc = file.WriteInt( m_type );
        if (!rc) break;
        rc = file.WriteArray( m_fsi );
        if (!rc) break;
        rc = file.WriteBoundingBox( m_bbox );
        if (!rc) break;

        break;
    }
    if (!file.EndWrite3dmChunk())
        rc = false;
    return rc;
}
Esempio n. 24
0
// virtual ON_Object override
ON_BOOL32 ON__IDefAlternativePathUserData::Write(ON_BinaryArchive& binary_archive) const
{
  bool rc = binary_archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
  if ( !rc )
    return false;

  rc = false;
  for(;;)
  {
    if ( !binary_archive.WriteString(m_alternate_path) )
      break;
    if ( !binary_archive.WriteBool(m_bRelativePath) )
      break;
    rc = true;
    break;
  }

  if ( !binary_archive.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
Esempio n. 25
0
bool ON_ClippingPlane::Write( ON_BinaryArchive& file ) const
{
  bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
  if (!rc)
    return false;

  for(;;)
  {
    //version 1.1 - write list of viewport uuids instead of single uuid
    ON_UUID viewport_id = ::ON_nil_uuid;
    if( m_viewport_ids.Count() > 0 )
      viewport_id = *(m_viewport_ids.Array());
    rc = file.WriteUuid(viewport_id);
    if (!rc) break;

    rc = file.WriteUuid(m_plane_id);
    if (!rc) break;

    rc = file.WritePlane(m_plane);
    if (!rc) break;

    rc = file.WriteBool(m_bEnabled);
    if (!rc) break;

    //version 1.1 - write list of viewport uuids instead of single uuid
    rc = m_viewport_ids.Write(file);
    if (!rc) break;

    break;
  }

  if ( !file.EndWrite3dmChunk() )
    rc = false;

  return rc;
}
ON_BOOL32 ON_3dmProperties::Write(ON_BinaryArchive& file) const
{
    ON_BOOL32 rc = true;

    // This short chunk identifies the version of OpenNURBS that was used to write this file.
    rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_OPENNURBS_VERSION,ON::Version());
    if ( rc) rc = file.EndWrite3dmChunk();

    // optional TCODE_PROPERTIES_REVISIONHISTORY chunk - file creation/revision information
    if ( rc && m_RevisionHistory.IsValid() ) {
        rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_REVISIONHISTORY,0);
        if ( rc ) {
            rc = m_RevisionHistory.Write(file);
            if ( !file.EndWrite3dmChunk() )
                rc = false;
        }
    }

    // optional TCODE_PROPERTIES_NOTES chunk - file notes
    if ( rc && m_Notes.IsValid() ) {
        rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_NOTES,0);
        if ( rc ) {
            rc = m_Notes.Write(file);
            if ( !file.EndWrite3dmChunk() )
                rc = false;
        }
    }

    // optional TCODE_PROPERTIES_PREVIEWIMAGE chunk - bitmap preview
    //if ( rc && m_PreviewImage.IsValid() ) {
    //  rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_PREVIEWIMAGE,0);
    //  if ( rc ) {
    //    rc = m_PreviewImage.WriteUncompressed(file);
    //    if ( !file.EndWrite3dmChunk() )
    //      rc = false;
    //  }
    //}

    // optional TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE chunk - bitmap preview
    if ( rc && m_PreviewImage.IsValid() ) {
        rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE,0);
        if ( rc ) {
            rc = m_PreviewImage.WriteCompressed(file);
            if ( !file.EndWrite3dmChunk() )
                rc = false;
        }
    }

    // optional TCODE_PROPERTIES_APPLICATION chunk - application information
    if ( rc && m_Application.IsValid() ) {
        rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_APPLICATION,0);
        if ( rc ) {
            rc = m_Application.Write(file);
            if ( !file.EndWrite3dmChunk() )
                rc = false;
        }
    }

    // required TCODE_ENDOFTABLE chunk - marks end of properties table
    if ( rc ) {
        rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 );
        if ( rc ) {
            if ( !file.EndWrite3dmChunk() )
                rc = false;
        }
    }

    return rc;
}
Esempio n. 27
0
BOOL ON_Brep::Write( ON_BinaryArchive& file ) const
{
  const ON_Brep* brep = this;
  ON_Brep* v2brep = 0;

  if ( file.Archive3dmVersion() <= 2 && !IsValidForV2() )
  {
    v2brep = ON_Brep::New(*this);
    v2brep->MakeValidForV2();
    brep = v2brep;
  }

  //BOOL rc = file.Write3dmChunkVersion(3,0); // serialization version
  //BOOL rc = file.Write3dmChunkVersion(3,1); // added meshes
  BOOL rc = file.Write3dmChunkVersion(3,2); // added m_is_solid

  // 2d curves
  if (rc) rc = brep->m_C2.Write(file);

  // 3d curves
  if (rc) rc = brep->m_C3.Write(file);

  // untrimmed surfaces
  if (rc) rc = brep->m_S.Write(file);

  // vertices
  if (rc) rc = brep->m_V.Write(file);

  // edges
  if (rc) rc = brep->m_E.Write(file);

  // trims
  if (rc) rc = brep->m_T.Write(file);

  // loops
  if (rc) rc = brep->m_L.Write(file);

  // faces
  if (rc) rc = brep->m_F.Write(file);

  // bounding box
  if (rc) rc = file.WritePoint( brep->m_bbox.m_min );
  if (rc) rc = file.WritePoint( brep->m_bbox.m_max );

  // end of chunk version 3.0

  if (rc)
  {
    // added for chunk version 3.1
    const int face_count = brep->m_F.Count();
    int fi;
    unsigned char b;

    // write render meshes
    rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
    if ( rc )
    {
      for ( fi = 0; rc && fi < face_count; fi++ ) {
        const ON_Mesh* mesh = file.Save3dmRenderMeshes() ? brep->m_F[fi].m_render_mesh : 0;
        b = mesh ? 1 : 0;
        file.WriteChar(b);
        if (mesh) {
          rc = file.WriteObject(*mesh);
        }
      }
      if ( !file.EndWrite3dmChunk() )
      {
        rc = false;
      }
    }

    // write analysis meshes
    rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
    if ( rc )
    {
      for ( fi = 0; rc && fi < face_count; fi++ ) {
        const ON_Mesh* mesh = file.Save3dmAnalysisMeshes() ? brep->m_F[fi].m_analysis_mesh : 0;
        b = mesh ? 1 : 0;
        file.WriteChar(b);
        if (mesh) {
          rc = file.WriteObject(*mesh);
        }
      }
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }

  }
  // end of chunk version 3.1

  // use value of "this" m_is_solid to avoid expensive
  // calculation on the v2brep
  if ( !file.WriteInt( m_is_solid ) )
    rc = false;
  // end of chunk version 3.2

  if ( 0 != v2brep )
    delete v2brep;

  return rc;
}
bool ON_3dmProperties::Write(ON_BinaryArchive& file) const
{
  bool rc = true;

  // This short chunk identifies the version of OpenNURBS that was used to write this file.
  const unsigned int version_number_to_write = ON_BinaryArchive::ArchiveOpenNURBSVersionToWrite(file.Archive3dmVersion(), ON::Version());
  rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_OPENNURBS_VERSION, version_number_to_write);
  if (rc)
    rc = file.EndWrite3dmChunk();
  if (!rc)
    return false;

  // This chunk added November 5, 2015
  const ON_wString archive_full_path
    = file.ArchiveFullPath().IsEmpty()
    ? m_3dmArchiveFullPathName
    : file.ArchiveFullPath();
  if (archive_full_path.IsNotEmpty())
  {
    if (!file.BeginWrite3dmChunk(TCODE_PROPERTIES_AS_FILE_NAME, 0))
      return false;
    rc = file.WriteString(file.ArchiveFullPath());
    if (!file.EndWrite3dmChunk())
      rc = false;
    if (!rc)
      return false;
  }


  // optional TCODE_PROPERTIES_REVISIONHISTORY chunk - file creation/revision information
  if ( rc && m_RevisionHistory.IsValid() ) {
    rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_REVISIONHISTORY,0);
    if ( rc ) {
      rc = m_RevisionHistory.Write(file);
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }
  }

  // optional TCODE_PROPERTIES_NOTES chunk - file notes
  if ( rc && m_Notes.IsValid() ) {
    rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_NOTES,0);
    if ( rc ) {
      rc = m_Notes.Write(file);
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }
  }

  //// When merging Mac code please note that the
  //// TCODE_PROPERTIES_PREVIEWIMAGE chunk is OBSOLETE.
  //// DO NOT WRITE THEM IN V6 FILES.  If performance is an
  //// issue, we will address it some other way.

  // optional TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE chunk - bitmap preview
  if ( rc && m_PreviewImage.IsValid() && file.Save3dmPreviewImage()) 
  {
    rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE,0);
    if ( rc ) 
    {
      rc = m_PreviewImage.WriteCompressed(file);
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }
  }

  // optional TCODE_PROPERTIES_APPLICATION chunk - application information
  if ( rc && m_Application.IsValid() ) 
  {
    rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_APPLICATION,0);
    if ( rc ) 
    {
      rc = m_Application.Write(file);
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }
  }

  // required TCODE_ENDOFTABLE chunk - marks end of properties table
  if ( rc ) {
    rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 );
    if ( rc ) {
      if ( !file.EndWrite3dmChunk() )
        rc = false;
    }
  }

  return rc;
}