Exemplo n.º 1
0
void ON_UserData::Dump( ON_TextLog& text_log ) const
{
  text_log.Print("User Data:\n");
  text_log.PushIndent();

  // print class name and class uuid
  ON_Object::Dump(text_log);

  // developer's user data description
  ON_wString description;
  const_cast<ON_UserData*>(this)->GetDescription(description);
  if ( description.IsEmpty() )
    description = L"none";
  const wchar_t* ws = description;
  text_log.Print("user data description: %S\n",ws);
  text_log.Print("user data uuid: ");
  text_log.Print(m_userdata_uuid);
  text_log.Print("\n");
  text_log.Print("user data copy count: %d\n",this->m_userdata_copycount);

  // archive setting
  text_log.Print("user data saved in 3dm archive: %s\n",Archive() ? "yes" : "no");

  text_log.PopIndent();
}
CRhinoCommand::result CCommandSampleOpenIges::RunCommand( const CRhinoCommandContext& context )
{
  ON_wString filename;

  if( context.IsInteractive() )
  {
    DWORD dwFlags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
    const wchar_t* szFilter = L"IGES Files (*.igs;*.iges)|*.igs; *.iges||";
    CWnd* pParentWnd = CWnd::FromHandle( RhinoApp().MainWnd() );

#if defined(WIN64)
    CFileDialog dialog( TRUE, L"igs", 0, dwFlags, szFilter, pParentWnd, 0, TRUE );
#else
    CFileDialog dialog( TRUE, L"igs", 0, dwFlags, szFilter, pParentWnd );
#endif
    INT_PTR rc = dialog.DoModal();
    if( rc != IDOK )
      return CRhinoCommand::cancel;

    filename = dialog.GetPathName();
  }
  else
  {
    CRhinoGetString gs;
    gs.SetCommandPrompt( L"IGES file to open" );
    gs.GetString();
    if( gs.CommandResult() != CRhinoCommand::success )
      return gs.CommandResult();

    filename = gs.String();
  }

  filename.TrimLeftAndRight();
  if( filename.IsEmpty() )
    return CRhinoCommand::nothing;

  if( !CRhinoFileUtilities::FileExists(filename) )
  {
    RhinoApp().Print( L"File \"%s\" not found.\n", filename );
    return CRhinoCommand::failure;
  }

  // Note, setting the document modified flag to false will prevent the
  // "Do you want to save this file..." mesasge from displaying when you
  // open a file (if the current document has been modified in any way).
  // But, you will (also) loose any modifications to the current document.
  // So, use the following line of code carefully.
  context.m_doc.SetModifiedFlag( FALSE );

  ON_wString script;
  script.Format( L"_-Open \"%s\" _Enter _Enter _Enter", filename );

  RhinoApp().RunScript( script, 0 );

  return CRhinoCommand::success;
}
Exemplo n.º 3
0
bool ON_InstanceDefinition::GetAlternateSourceArchivePath( 
      ON_wString& alternate_source_archive_path,
      bool& bRelativePath
      ) const
{
  const ON__IDefAlternativePathUserData* ud = ON__IDefAlternativePathUserData::FindOrCreate(*this,false);
  const wchar_t* s = (0 != ud) ? ((const wchar_t*)ud->m_alternate_path) : 0;
  if ( 0 != s && 0 != s[0] )
  {
    alternate_source_archive_path = s;
    bRelativePath = ud->m_bRelativePath;
  }
  else
  {
    alternate_source_archive_path.Destroy();
    bRelativePath = false;
  }
  return !alternate_source_archive_path.IsEmpty();
}
Exemplo n.º 4
0
// virtual ON_UserData override
ON_BOOL32 ON__IDefAlternativePathUserData::Archive() const
{
  // don't save empty settings
  return !m_alternate_path.IsEmpty();
}
Exemplo n.º 5
0
// virtual ON_Object override
ON_BOOL32 ON__IDefAlternativePathUserData::IsValid( ON_TextLog* text_log ) const
{
  return !m_alternate_path.IsEmpty();
}
CRhinoCommand::result CCommandSampleImportMeshes::RunCommand( const CRhinoCommandContext& context )
{
  CWnd* pMainWnd = CWnd::FromHandle(RhinoApp().MainWnd());
  if (0 == pMainWnd)
    return CRhinoCommand::failure;
 
  CRhinoGetFileDialog gf;
  gf.SetScriptMode(context.IsInteractive() ? FALSE : TRUE);
  BOOL rc = gf.DisplayFileDialog(CRhinoGetFileDialog::open_rhino_only_dialog, 0, pMainWnd);
  if (!rc)
    return CRhinoCommand::cancel;
 
  ON_wString filename = gf.FileName();
  filename.TrimLeftAndRight();
  if (filename.IsEmpty())
    return CRhinoCommand::nothing;

  if (!CRhinoFileUtilities::FileExists(filename))
  {
    RhinoApp().Print(L"File not found\n");
    return CRhinoCommand::failure;
  }

  FILE* archive_fp = ON::OpenFile(filename, L"rb");
  if (0 == archive_fp)
  {
    RhinoApp().Print(L"Unable to open file\n");
    return CRhinoCommand::failure;
  }

  ON_BinaryFile archive(ON::read3dm, archive_fp);

  ONX_Model model;
  rc = model.Read(archive) ? TRUE : FALSE;

  ON::CloseFile( archive_fp );

  if (!rc)
  {
    RhinoApp().Print(L"Error reading file\n");
    return CRhinoCommand::failure;
  }

  int num_imported = 0;
  for (int i = 0; i < model.m_object_table.Count(); i++)
  {
    const ONX_Model_Object& model_object = model.m_object_table[i];
    const ON_Mesh* mesh = ON_Mesh::Cast(model_object.m_object);
    if (0 != mesh)
    {
      // CRhinoDoc::AddMeshObject makes a copy of the input mesh
      context.m_doc.AddMeshObject(*mesh);
      num_imported++;
    }
  }

  if (0 == num_imported)
    RhinoApp().Print(L"No meshes imported\n");
  else if (1 == num_imported)
    RhinoApp().Print(L"1 mesh imported\n");
  else
    RhinoApp().Print(L"%d meshes imported\n", num_imported);

  context.m_doc.Redraw();

  return CRhinoCommand::success;
}