Exemple #1
0
/**
 *			R T _ B R E P _ D E S C R I B E
 */
int
rt_brep_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
{
    BU_CK_VLS(str);
    RT_CK_DB_INTERNAL(ip);

    ON_wString wonstr;
    ON_TextLog log(wonstr);

    struct rt_brep_internal* bi;
    bi = (struct rt_brep_internal*)ip->idb_ptr;
    RT_BREP_CK_MAGIC(bi);
    if (bi->brep != NULL)
	bi->brep->Dump(log);

    ON_String onstr = ON_String(wonstr);
    bu_vls_strcat(str, "Boundary Representation (BREP) object\n");

    const char *description = onstr.Array();
    // skip the first "ON_Brep:" line
    while (description && description[0] && description[0] != '\n') {
	description++;
    }
    if (description && description[0] && description[0] == '\n') {
	description++;
    }
    bu_vls_strcat(str, description);

    return 0;
}
ON_String ON_String::Left(int count) const
{
  ON_String s;
  if ( count > Length() )
    count = Length();
  if ( count > 0 ) {
    s.CopyToArray( count, m_s );
  }
  return s;
}
ON_String ON_String::Right(int count) const
{
  ON_String s;
  if ( count > Length() )
    count = Length();
  if ( count > 0 ) {
    s.CopyToArray( count, &m_s[Length()-count] );
  }
  return s;
}
Exemple #4
0
bool ON_Base32ToString( const ON_SimpleArray<unsigned char>& base32_digits, ON_String& sBase32 )
{
  int digit_count = base32_digits.Count();
  sBase32.ReserveArray(digit_count);
  sBase32.SetLength(digit_count);
  bool rc = ON_Base32ToString( base32_digits, digit_count, sBase32.Array() );
  if (!rc)
    sBase32.SetLength(0);
  return rc;
}
Exemple #5
0
ON_String::ON_String(const ON_String& src)
{
	if ( src.Header()->ref_count > 0 )	{
		m_s = src.m_s;
    src.Header()->ref_count++;
	}
	else {
		Create();
		*this = src.m_s; // use operator=(const char*) to copy
	}
}
Exemple #6
0
int ON_CorrectBase32StringTypos( const wchar_t* sBase32, ON_wString& sBase32clean )
{
  if ( 0 == sBase32 || 0 == sBase32[0] )
    return 0;
  ON_String s = sBase32;
  int length = ON_CorrectBase32StringTypos(s.Array(),s.Array());
  if ( length > 0 )
    sBase32clean = s;
  else
    sBase32clean.SetLength(0);
  return length;
}
Exemple #7
0
void ON_TextLog::PrintPointList( int dim, int is_rat, int count, int stride, const double* P,
                                const char* sPreamble )
{
  double w, x;
  int i, j, cvdim;

  ON_String preamble = "";
  if ( sPreamble && *sPreamble )
    preamble += sPreamble;
  cvdim = (is_rat) ? dim+1 : dim;

  if ( count == 0 ) {
    Print( "%sEMPTY point list\n", preamble.Array() );
  }
  else if ( !P ) {
    Print( "%sNULL point list\n", preamble.Array() );
  }

  for ( i = 0; i < count; i++ ) {
    Print( "%s[%2d] %c", preamble.Array(), i, (is_rat) ? '[' : '(' );
    Print( m_double_format, P[0] );
    for ( j = 1; j < cvdim; j++ ) {
      Print( ", ");
      Print(m_double_format, P[j] );
    }
    Print("%c", (is_rat) ? ']' : ')' );
    if ( is_rat ) 
    {
      w = P[dim];
      if ( w != 0.0 ) 
      {
        // print euclidean coordinates
        w = 1.0/w;
        x = w*P[0];
        Print( " = (");
        Print( m_double_format, x );
        for ( j = 1; j < dim; j++ ) 
        {
          x = w*P[j];
          Print( ", ");
          Print( m_double_format, x );
        }
        Print(")");
      }
    }
    Print("\n");
    P += stride;
  }
}
static bool HasErrorsOrWarnings(ON_TextLog* log, const char* operation)
{
  ON_String msg;
  if (ON_GetErrorCount() > 0)
  {
    msg.Format("%d errors: %s", ON_GetErrorCount(), operation);
    log->Print(msg);
    return true;
  }
  if (ON_GetWarningCount() > 0)
  {
    msg.Format("%d warnings: %s", ON_GetErrorCount(), operation);
    log->Print(msg);
    return true;
  }
  return false;
}
void ON_TextLog::AppendText( const wchar_t* s )
{
  // This is a virtual function 
  if ( m_pString )
  {
    (*m_pString) += s;
  }
  else
  {
    // If sizeof(wchar_t) = 2, str = s performs
    // performs UTF-16 to UTF-8 conversion.
    // If sizeof(wchar_t) = 4, str = s performs
    // performs UTF-32 to UTF-8 conversion.
    ON_String str = s;
    AppendText(str.Array());
  }
}
Exemple #10
0
void ON_TextLog::AppendText( const wchar_t* s )
{
  // This is a virtual function 
  if ( m_pString )
  {
    (*m_pString) += s;
  }
  else
  {
    // To properly handle conversion of UNICODE values > 255, 
    // you will probably have to derive a class from ON_TextLog, 
    // override ON_TextLog::AppendText(const wchar_t* s ),
    // and do whatever is appropriate for your OS and compiler.
    ON_String str = s;
    AppendText(str.Array());
  }
}
Exemple #11
0
int ON_StringToBase32(const ON_String& sBase32, ON_SimpleArray<unsigned char>& base32_digits )
{
  const char* s = sBase32;
  if ( 0 == s || 0 == s[0] )
    return 0;
  base32_digits.Reserve(sBase32.Length());
  int digit_count = ON_StringToBase32(sBase32,base32_digits.Array());
  base32_digits.SetCount(digit_count);
  return digit_count;
}
bool ON::IsDirectory( const char* utf8pathname )
{
  bool rc = false;

  if ( 0 != utf8pathname && 0 != utf8pathname[0] )
  {
    ON_String buffer;
    const char* stail = utf8pathname;
    while ( 0 != *stail )
      stail++;
    stail--;
    if ( '\\' == *stail || '/' == *stail ) 
    {
      const char trim[2] = {*stail,0};
      buffer = utf8pathname;
      buffer.TrimRight(trim);
      if ( buffer.Length() > 0 )
        utf8pathname = buffer;
    }
#if defined(ON_COMPILER_MSC)
    // this works on Windows
    struct _stat64 buf;
    memset(&buf,0,sizeof(buf));
    int stat_errno = _stat64( utf8pathname, &buf );
    if ( 0 == stat_errno && 0 != (_S_IFDIR & buf.st_mode) )
    {
      rc = true;
    }
#else
    // this works on Apple and gcc implentations.
    struct stat buf;
    memset(&buf,0,sizeof(buf));
    int stat_errno = stat( utf8pathname, &buf );
    if ( 0 == stat_errno && S_ISDIR(buf.st_mode) )
    {
      rc = true;
    }
#endif
  }

  return rc;
}
Exemple #13
0
static bool Internal_Parse_ParsOption_RECURSE(const char* s, unsigned int& N)
{
  const char* tail = Internal_ParseOptionHead(s, "r", "recurse", "recursive" );
  if (nullptr == tail)
    return false;

  if (0 == tail[0])
  {
    N = 16; // sanity limit of default directory recursion depth
    return true;
  }

  N = 0;
  const ON_String num = Internal_ParseOptionTail(tail);
  if (num.IsNotEmpty())
  {
    unsigned int u = 0;
    const char* s1 = ON_String::ToNumber(num, u, &u);
    if (nullptr != s1 && s1 > static_cast<const char*>(num) && u >= 1 && 0 == s1[0])
      N = u;
  }
  return true;
}
Exemple #14
0
int ON_CorrectBase32StringTypos( const char* sBase32, ON_String& sBase32clean )
{
  char* sClean = 0;
  if ( sBase32 == sBase32clean.Array() )
    sClean = sBase32clean.Array();
  else
  {
    sBase32clean.SetLength(0);
    sBase32clean.ReserveArray(strlen(sBase32));
    sClean = sBase32clean.Array();
  }
  int length = ON_CorrectBase32StringTypos( sBase32, sClean );
  sBase32clean.SetLength(length);
  return length;
}
void ON_String::AppendToArray( const ON_String& s )
{
  AppendToArray( s.Length(), s.Array() );
}
void ON_String::CopyToArray( const ON_String& s )
{
  CopyToArray( s.Length(), s.Array() );
}
int main( int argc, const char *argv[] )
{
    // If you are using OpenNURBS as a Windows DLL, then you MUST use
    // ON::OpenFile() to open the file.  If you are not using OpenNURBS
    // as a Windows DLL, then you may use either ON::OpenFile() or fopen()
    // to open the file.

    int argi;
    if ( argc < 2 )
    {
        printf("Syntax: %s [-out:outputfilename.txt] file1.3dm file2.3dm ...\n",argv[0] );
        return 0;
    }

    // Call once in your application to initialze opennurbs library
    ON::Begin();

    // default dump is to stdout
    ON_TextLog dump_to_stdout;
    ON_TextLog* dump = &dump_to_stdout;
    FILE* dump_fp = 0;

    ONX_Model model;

    for ( argi = 1; argi < argc; argi++ )
    {
        const char* arg = argv[argi];

        // check for -out or /out option
        if ( ( 0 == strncmp(arg,"-out:",5) || 0 == strncmp(arg,"/out:",5) )
                && arg[5] )
        {
            // change destination of dump file
            const char* sDumpFilename = arg+5;
            FILE* text_fp = ON::OpenFile(sDumpFilename,"w");
            if ( text_fp )
            {
                if ( dump_fp )
                {
                    delete dump;
                    ON::CloseFile(dump_fp);
                }
                dump_fp = text_fp;
                dump = new ON_TextLog(dump_fp);
            }
            continue;
        }

        const char* sFileName = arg;

        dump->Print("\nOpenNURBS Archive File:  %s\n", sFileName );

        // open file containing opennurbs archive
        FILE* archive_fp = ON::OpenFile( sFileName, "rb");
        if ( !archive_fp )
        {
            dump->Print("  Unable to open file.\n" );
            continue;
        }

        dump->PushIndent();

        // create achive object from file pointer
        ON_BinaryFile archive( ON::read3dm, archive_fp );

        // read the contents of the file into "model"
        bool rc = model.Read( archive, dump );

        // close the file
        ON::CloseFile( archive_fp );

        // print diagnostic
        if ( rc )
            dump->Print("Successfully read.\n");
        else
            dump->Print("Errors during reading.\n");

        // see if everything is in good shape
        if ( model.IsValid(dump) )
            dump->Print("Model is valid.\n");
        else
        {
            model.Polish();
            if ( model.IsValid() )
            {
                dump->Print("Model is valid after calling Polish().\n");
            }
            else
            {
                dump->Print("Model is not valid.\n");
            }
        }

        /*
        int oi = 14;
        if ( oi >=0 && oi < model.m_object_table.Count() )
        {
          dump->Print("m_object_table[%d].m_object:\n",oi);
          dump->PushIndent();
          model.m_object_table[oi].m_object->Dump(*dump);
          dump->PopIndent();
        }
        */

        int version = 0; // write current Rhino file

        ON_String outfile = sFileName;
        int len = outfile.Length() - 4;
        outfile.SetLength(len);
        outfile += "_roundtrip.3dm";
        bool outrc = model.Write( outfile, version, "roundtrip", dump );
        if ( outrc )
        {
            dump->Print("model.Write(%s) succeeded.\n",outfile.Array());
            ONX_Model model2;
            if ( model2.Read( outfile, dump ) )
            {
                dump->Print("model2.Read(%s) succeeded.\n",outfile.Array());
                if ( model2.IsValid(dump) )
                {
                    dump->Print("Model2 is valid.\n");
                }
                else
                {
                    dump->Print("Model2 is not valid.\n");
                }
                /*
                if ( oi >=0 && oi < model2.m_object_table.Count() )
                {
                  dump->Print("m_object_table[%d].m_object:\n",oi);
                  dump->PushIndent();
                  model2.m_object_table[oi].m_object->Dump(*dump);
                  dump->PopIndent();
                }
                */
            }
            else
            {
                dump->Print("model2.Read(%s) failed.\n",outfile.Array());
            }
        }
        else
            dump->Print("model.Write(%s) failed.\n",outfile.Array());

        // destroy this model
        model.Destroy();

        dump->PopIndent();
    }

    if ( dump_fp )
    {
        // close the text dump file
        delete dump;
        ON::CloseFile( dump_fp );
    }

    // OPTIONAL: Call just before your application exits to clean
    //           up opennurbs class definition information.
    //           Opennurbs will not work correctly after ON::End()
    //           is called.
    ON::End();

    return 0;
}
int main(int argc, const char *argv[])
{
  // If you are using OpenNURBS as a Windows DLL, then you MUST use
  // ON::OpenFile() to open the file.  If you are not using OpenNURBS
  // as a Windows DLL, then you may use either ON::OpenFile() or fopen()
  // to open the file.

  int argi;
  if (argc < 2)
  {
    Usage(argv[0]);
    return 0;
  }

  // Call once in your application to initialze opennurbs library
  ON::Begin();

  int version = 0; // write current Rhino file

                   // default dump is to stdout
  ON_TextLog dump_to_stdout;
  ON_TextLog* dump = &dump_to_stdout;

  ON_String input;
  ON_String output;
  ON_String logfile;

  for (argi = 1; argi < argc; argi++)
  {
    ON_String arg(argv[argi]);

    if (arg.Left(10).CompareOrdinal("--version=", true) == 0)
    {
      arg = arg.Mid(10);
      version = atoi(arg);
      continue;
    }

    if (arg.Left(2).CompareOrdinal("/v", true) == 0 || arg.Left(2).CompareOrdinal("-v", true) == 0)
    {
      argi++;
      const char* sversion = argv[argi];
      version = atoi(sversion);
      continue;
    }

    if (arg.Left(6).CompareOrdinal("--log=", true) == 0)
    {
      arg = arg.Mid(6);
      logfile = arg;
      continue;
    }

    if (input.IsEmpty())
    {
      input = arg;
      if (false == ON_FileStream::Is3dmFile(input, true))
      {
        input = ON_String::EmptyString;
        break;
      }
      continue;
    }

    if (output.IsEmpty())
    {
      output = arg;
      continue;
    }

    // Invalid command line parameter
    input = ON_String::EmptyString;
    output = ON_String::EmptyString;
    break;
  }

  if (input.IsEmpty() || output.IsEmpty())
  {
    Usage(argv[0]);
    return 1;
  }


  dump->Print("\nOpenNURBS Archive File:  %s\n", static_cast<const char*>(input) );

  // open file containing opennurbs archive
  FILE* archive_fp = ON_FileStream::Open3dmToRead(input);
  if (nullptr == archive_fp)
  {
    dump->Print("  Unable to open file.\n");
    return 1;
  }

  dump->PushIndent();

  // create achive object from file pointer
  ON_BinaryFile archive(ON::archive_mode::read3dm, archive_fp);

  // read the contents of the file into "model"
  ONX_Model model;
  bool rc = model.Read(archive, dump);
  // close the file
  ON::CloseFile(archive_fp);

  if (false == rc)
  {
    dump->Print("Errors during reading.\n");
    return 1;
  }

  if (HasErrorsOrWarnings(dump, "reading input file"))
    return 1;
  
  // print diagnostic
  dump->Print("Successfully read.\n");
  
  // Write file
  model.m_sStartSectionComments = "Converted by example_convert.exe";
  bool outrc = model.Write(output, version, dump);
  if (HasErrorsOrWarnings(dump, "writing output file"))
    return 1;
  
  if (outrc)
  {
    dump->Print("model.Write(%s) succeeded.\n", static_cast<const char*>(output));
    ONX_Model model2;
    if (model2.Read(output, dump))
    {
      dump->Print("model2.Read(%s) succeeded.\n", static_cast<const char*>(output));
      if (HasErrorsOrWarnings(dump, "verifying output file"))
        return 1;

      if (!logfile.IsEmpty())
      {
        FILE* fp = ON::OpenFile(logfile, "w");
        ON_TextLog log(fp);
        model2.Dump(log);
        ON::CloseFile(fp);
      }

    }
    else
    {
      dump->Print("model2.Read(%s) failed.\n", static_cast<const char*>(output));
    }

    dump->PopIndent();
  }

  // OPTIONAL: Call just before your application exits to clean
  //           up opennurbs class definition information.
  //           Opennurbs will not work correctly after ON::End()
  //           is called.
  ON::End();

  return 0;
}
Exemple #19
0
ON_wString ON_wString::operator+(const ON_String& s2) const
{
	ON_wString s(*this);
  s.AppendToArray( s2.Length(), s2.Array() );
	return s;
}