opennurbs_linetype.cpp
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018 
00019 bool ON_IsHairlinePrintWidth(double width_mm)
00020 {
00021   if(width_mm > 0.0 && width_mm < 0.001)
00022     return true;
00023 
00024   return false;
00025 }
00026 
00027 double ON_HairlinePrintWidth()
00028 {
00029   return 0.0001;
00030 }
00031 
00032 
00034 // class ON_LinetypeSegment
00035 bool ON_LinetypeSegment::operator==( const ON_LinetypeSegment& src) const
00036 {
00037   return ( m_length == src.m_length && m_seg_type == src.m_seg_type);
00038 }
00039 
00040 bool ON_LinetypeSegment::operator!=( const ON_LinetypeSegment& src) const
00041 {
00042   return ( m_length != src.m_length || m_seg_type != src.m_seg_type);
00043 }
00044 
00045 
00046 void ON_LinetypeSegment::Dump( ON_TextLog& dump) const
00047 {
00048   switch( m_seg_type)
00049   {
00050   case stLine:
00051     dump.Print( "Segment type = Line: %g\n", m_length);
00052     break;
00053   case stSpace:
00054     dump.Print( "Segment type = Space: %g\n", m_length);
00055     break;
00056   }
00057 }
00058 
00059 ON_LinetypeSegment::ON_LinetypeSegment()
00060 {
00061   memset(this,0,sizeof(*this));
00062   m_length = 1.0;
00063   m_seg_type = stLine;
00064 }
00065 
00067 // class ON_Linetype
00068 
00069 ON_OBJECT_IMPLEMENT( ON_Linetype, ON_Object, "26F10A24-7D13-4f05-8FDA-8E364DAF8EA6" );
00070 
00071 ON_Linetype::ON_Linetype() : m_linetype_index(-1)
00072 {
00073   memset(&m_linetype_id,0,sizeof(m_linetype_id));
00074 }
00075 
00076 ON_Linetype::~ON_Linetype()
00077 {
00078   m_linetype_name.Destroy();
00079 }
00080 
00081 void ON_Linetype::Default()
00082 {
00083   m_linetype_index = -1;
00084   memset(&m_linetype_id,0,sizeof(m_linetype_id));
00085   m_linetype_name.Destroy();
00086   m_segments.Destroy();
00087 }
00088 
00089 ON_BOOL32 ON_Linetype::IsValid( ON_TextLog* text_log ) const
00090 {
00091   int i, count = m_segments.Count();
00092 
00093   // An ON_Linetype with an empty name is valid.
00094 
00095   if ( count < 1 )
00096   {
00097     if ( text_log )
00098       text_log->Print("ON_Linetype m_segments.Count() = 0\n");
00099     return false;
00100   }
00101 
00102   if ( 1 == count )
00103   {
00104     if ( m_segments[0].m_length <= 0.0  )
00105     {
00106       if ( text_log )
00107         text_log->Print("ON_Linetype bogus single segment linetype - length <= 0.0 (it must be > 0)\n");
00108       return false;
00109     }
00110 
00111     if ( ON_LinetypeSegment::stLine != m_segments[0].m_seg_type )
00112     {
00113       if ( text_log )
00114         text_log->Print("ON_Linetype bogus single segment linetype - type != stLine\n");
00115       return false;
00116     }
00117   }
00118   else
00119   {
00120     for (i = 0; i < count; i++ )
00121     {
00122       if ( m_segments[i].m_length < 0.0 )
00123       {
00124         if ( text_log )
00125           text_log->Print("ON_Linetype segment has negative length.\n");
00126         return false;
00127       }
00128 
00129       if ( ON_LinetypeSegment::stLine != m_segments[i].m_seg_type && ON_LinetypeSegment::stSpace != m_segments[i].m_seg_type )
00130       {
00131         if ( text_log )
00132           text_log->Print("ON_Linetype segment has invalid m_seg_type.\n");
00133         return false;
00134       }
00135 
00136       if ( i )
00137       {
00138         if ( m_segments[i].m_seg_type == m_segments[i-1].m_seg_type )
00139         {
00140           if ( text_log )
00141             text_log->Print("ON_Linetype consecutive segments have same type.\n");
00142           return false;
00143         }
00144 
00145         if ( 0.0 == m_segments[i].m_length && 0.0 == m_segments[i-1].m_length )
00146         {
00147           if ( text_log )
00148             text_log->Print("ON_Linetype consecutive segments have length zero.\n");
00149           return false;
00150         }
00151       }
00152     }
00153   }
00154 
00155   return true;
00156 }
00157 
00158 void ON_Linetype::Dump( ON_TextLog& dump ) const
00159 {
00160   const wchar_t* sName = LinetypeName();
00161   if ( !sName )
00162     sName = L"";
00163   dump.Print( "Segment count = %d\n", m_segments.Count());
00164   dump.Print( "Pattern length = %g\n", PatternLength());
00165   dump.Print( "Pattern = (" );
00166   for( int i = 0; i < m_segments.Count(); i++)
00167   {
00168     const ON_LinetypeSegment& seg = m_segments[i];
00169     if ( i )
00170       dump.Print(",");
00171     switch( seg.m_seg_type)
00172     {
00173     case ON_LinetypeSegment::stLine:
00174       dump.Print( "line");
00175       break;
00176     case ON_LinetypeSegment::stSpace:
00177       dump.Print( "space");
00178       break;
00179     default:
00180       dump.Print( "invalid");
00181       break;
00182     }
00183   }
00184   dump.Print(")\n");
00185 }
00186 
00187 ON_BOOL32 ON_Linetype::Write( ON_BinaryArchive& file) const
00188 {
00189   bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
00190   if (rc)
00191   {
00192     for(;;)
00193     {
00194       // chunk version 1.0 fields
00195       rc = file.WriteInt( LinetypeIndex());
00196       if(!rc) break;
00197 
00198       rc = file.WriteString( m_linetype_name );
00199       if (!rc) break;
00200 
00201       rc = file.WriteArray( m_segments );
00202       if(!rc) break;
00203 
00204       // chunk version 1.1 fields
00205       rc = file.WriteUuid( m_linetype_id );
00206       if (!rc) break;
00207 
00208       break;
00209     }
00210 
00211     if ( !file.EndWrite3dmChunk() )
00212       rc = false;
00213   }
00214   return rc;
00215 }
00216 
00217 ON_BOOL32 ON_Linetype::Read( ON_BinaryArchive& file)
00218 {
00219   Default();
00220   m_linetype_index = -1;
00221 
00222   int major_version=0;
00223   int minor_version=0;
00224   bool rc = file.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version );
00225 
00226   if (rc)
00227   {
00228     if( 1 == major_version ) 
00229     {
00230       // chunk version 1.0 fields
00231       if( rc) 
00232         rc = file.ReadInt( &m_linetype_index );
00233       if( rc) 
00234         rc = file.ReadString( m_linetype_name );
00235       if( rc) 
00236         rc = file.ReadArray( m_segments );
00237 
00238       if ( minor_version >= 1 )
00239       {
00240         if (rc)
00241           rc = file.ReadUuid( m_linetype_id );
00242       }
00243     }
00244     else
00245     {
00246       rc = false;
00247     }
00248 
00249     if ( !file.EndRead3dmChunk() )
00250       rc = false;
00251   }
00252 
00253   return rc;
00254 }
00255 
00256 bool ON_Linetype::SetLinetypeName( const char* s)
00257 {
00258   m_linetype_name = s;
00259   return IsValid()?true:false;
00260 }
00261 
00262 bool ON_Linetype::SetLinetypeName( const wchar_t* s)
00263 {
00264   m_linetype_name = s;
00265   return IsValid()?true:false;
00266 }
00267 
00268 const wchar_t* ON_Linetype::LinetypeName() const
00269 {
00270   const wchar_t* s = m_linetype_name;
00271   return s;
00272 }
00273 
00274 bool ON_Linetype::SetLinetypeIndex( int i)
00275 {
00276   m_linetype_index = i;
00277   return true;
00278 }
00279 
00280 int ON_Linetype::LinetypeIndex() const
00281 {
00282   return m_linetype_index;
00283 }
00284 
00285 double ON_Linetype::PatternLength() const
00286 {
00287   double length = 0.0;
00288   int seg_count = m_segments.Count();
00289   for( int i = 0; i < seg_count; i++)
00290   {
00291     length += m_segments[i].m_length;
00292   }
00293   return length;
00294 }
00295 
00296 ON_SimpleArray<ON_LinetypeSegment>& ON_Linetype::Segments()
00297 {
00298   return m_segments;
00299 }
00300 
00301 const ON_SimpleArray<ON_LinetypeSegment>& ON_Linetype::Segments() const
00302 {
00303   return m_segments;
00304 }
00305 
00306 int ON_Linetype::SegmentCount() const
00307 {
00308   return m_segments.Count();
00309 }
00310 
00311 int ON_Linetype::AppendSegment( const ON_LinetypeSegment& segment)
00312 {
00313   m_segments.Append( segment);
00314   return( m_segments.Count()-1);
00315 }
00316 
00317 bool ON_Linetype::RemoveSegment( int index )
00318 {
00319   bool rc = ( index >= 0 && index < m_segments.Count());
00320   if (rc)
00321     m_segments.Remove(index);
00322   return rc;
00323 }
00324 
00325 bool ON_Linetype::SetSegment( int index, const ON_LinetypeSegment& segment)
00326 {
00327   if( index >= 0 && index < m_segments.Count())
00328   {
00329     m_segments[index] = segment;
00330     return true;
00331   }
00332   else
00333     return false;
00334 }
00335 
00336 bool ON_Linetype::SetSegment( int index, double length, ON_LinetypeSegment::eSegType type)
00337 {
00338   if( index >= 0 && index < m_segments.Count())
00339   {
00340     m_segments[index].m_length = length;
00341     m_segments[index].m_seg_type = type;
00342     return true;
00343   }
00344   else
00345     return false;
00346 }
00347 
00348 ON_LinetypeSegment ON_Linetype::Segment( int index) const
00349 {
00350   if( index >= 0 && index < m_segments.Count())
00351     return m_segments[index];
00352   else
00353     return ON_LinetypeSegment();
00354 }
00355 
00356 
00357 
00358 
00359 
00360 
00361 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:01