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 #ifndef OPENNURBS_HATCH_H_INCLUDED 00018 #define OPENNURBS_HATCH_H_INCLUDED 00019 00020 /* 00021 class ON_HatchLoop 00023 Represents a 3d boundary loop curve 00024 */ 00025 class ON_CLASS ON_HatchLoop 00026 { 00027 public: 00028 #if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS) 00029 // When the Microsoft CRT(s) is/are used, this is the best 00030 // way to prevent crashes that happen when a hatch loop is 00031 // allocated with new in one DLL and deallocated with 00032 // delete in another DLL. 00033 00034 // new/delete 00035 void* operator new(size_t); 00036 void operator delete(void*); 00037 00038 // array new/delete 00039 void* operator new[] (size_t); 00040 void operator delete[] (void*); 00041 00042 // in place new/delete 00043 void* operator new(size_t,void*); 00044 void operator delete(void*,void*); 00045 #endif 00046 00047 enum eLoopType 00048 { 00049 ltOuter = 0, 00050 ltInner = 1, 00051 }; 00052 00053 ON_HatchLoop(); 00054 ON_HatchLoop( ON_Curve* pCurve2d, eLoopType type = ltOuter); 00055 ON_HatchLoop( const ON_HatchLoop& src); 00056 ~ON_HatchLoop(); 00057 00058 ON_HatchLoop& operator=( const ON_HatchLoop& src); 00059 00060 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00061 void Dump( ON_TextLog& ) const; // for debugging 00062 ON_BOOL32 Write( ON_BinaryArchive&) const; 00063 ON_BOOL32 Read( ON_BinaryArchive&); 00064 00065 // Interface 00067 00068 /* 00069 Description: 00070 Get a closed 2d curve boundary loop 00071 Parameters: 00072 Return: 00073 Pointer to loop's 2d curve 00074 */ 00075 const ON_Curve* Curve() const; 00076 00077 /* 00078 Description: 00079 Specify the 2d loop curve in the hatch's plane coordinates 00080 Parameters: 00081 curve - [in] 2d input curve 00082 Return: 00083 true: success, false, curve couldn't be duplicated 00084 Remarks: 00085 The curve is copied 00086 */ 00087 bool SetCurve( const ON_Curve& curve); 00088 00089 /* 00090 Description: 00091 Get the type flag of the loop 00092 Returns: 00093 eLoopType::ltInner or eLoopType::ltOuter 00094 */ 00095 eLoopType Type() const; 00096 00097 /* 00098 Description: 00099 Specify the type flag of the loop 00100 Parameters: 00101 type - [in] ltInner or ltOuter 00102 */ 00103 void SetType( eLoopType type); 00104 00105 protected: 00106 friend class ON_Hatch; 00107 eLoopType m_type; // loop type flag - inner or outer 00108 ON_Curve* m_p2dCurve; // 2d closed curve bounding the hatch 00109 // This is really a 3d curve with z coordinates = 0 00110 }; 00111 00112 00113 /* 00114 class ON_HatchLine 00116 Represents one line of a hatch pattern 00117 Similar to AutoCAD's .pat file definition 00118 ON_HatchLine's are used by ON_HatchPattern 00119 to specify the dashes and offset patterns of the lines. 00120 00121 Each line has the following information: 00122 Angle is the direction of the line CCW from the x axis 00123 The first line origin is at base 00124 Each line repetition is offset by offset from the previous line 00125 offset.x is parallel to the line and 00126 offset.y is perpendicular to the line 00127 The base and offset values are rotated by the line's angle to 00128 produce a location in the hatch pattern's coordinate system 00129 There can be gaps and dashes specified for drawing the line 00130 00131 If there are no dashes, the line is solid 00132 Negative length dashes are gaps 00133 Positive length dashes are drawn as line segments 00134 */ 00135 00136 class ON_CLASS ON_HatchLine 00137 { 00138 public: 00139 ON_HatchLine(); 00140 // C++ default copy construction and operator= work fine. 00141 00142 ON_HatchLine( 00143 double angle, 00144 const ON_2dPoint& base, 00145 const ON_2dVector& offset, 00146 const ON_SimpleArray<double> dashes); 00147 00148 bool operator==( const ON_HatchLine&) const; 00149 bool operator!=( const ON_HatchLine&) const; 00150 00151 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00152 void Dump( ON_TextLog& ) const; // for debugging 00153 ON_BOOL32 Write( ON_BinaryArchive&) const; // serialize definition to binary archive 00154 ON_BOOL32 Read( ON_BinaryArchive&); // restore definition from binary archive 00155 00156 // Interface 00158 00159 /* 00160 Description: 00161 Get angle of the hatch line. 00162 CCW from x-axis 00163 Parameters: 00164 Return: 00165 The angle in radians 00166 */ 00167 double Angle() const; 00168 00169 /* 00170 Description: 00171 Set angle of the hatch line. 00172 CCW from x-axis 00173 Parameters: 00174 angle - [in] angle in radians 00175 Return: 00176 */ 00177 void SetAngle( double angle); 00178 00179 /* 00180 Description: 00181 Get this line's 2d basepoint 00182 Parameters: 00183 Return: 00184 the base point 00185 */ 00186 ON_2dPoint Base() const; 00187 /* 00188 Description: 00189 Set this line's 2d basepoint 00190 Parameters: 00191 base - [in] the basepoint 00192 Return: 00193 */ 00194 void SetBase( const ON_2dPoint& base); 00195 00196 /* 00197 Description: 00198 Get this line's 2d offset for line repetitions 00199 Offset().x is shift parallel to line 00200 Offset().y is spacing perpendicular to line 00201 Parameters: 00202 Return: 00203 the offset 00204 */ 00205 ON_2dVector Offset() const; 00206 00207 /* 00208 Description: 00209 Get this line's 2d offset for line repetitions 00210 Offset().x is shift parallel to line 00211 Offset().y is spacing perpendicular to line 00212 Parameters: 00213 offset - [in] the shift,spacing for repeated lines 00214 Return: 00215 */ 00216 void SetOffset( const ON_2dVector& offset); 00217 00218 /* 00219 Description: 00220 Get the number of gaps + dashes in the line 00221 Parameters: 00222 Return: 00223 nummber of dashes in the line 00224 */ 00225 int DashCount() const; 00226 00227 /* 00228 Description: 00229 Get the dash length at index 00230 Parameters: 00231 index - [in] the dash to get 00232 Return: 00233 the length of the dash ( gap if negative) 00234 */ 00235 double Dash( int) const; 00236 00237 /* 00238 Description: 00239 Add a dash to the pattern 00240 Parameters: 00241 dash - [in] length to append - < 0 for a gap 00242 */ 00243 void AppendDash( double dash); 00244 00245 /* 00246 Description: 00247 Specify a new dash array 00248 Parameters: 00249 dashes - [in] array of dash lengths 00250 */ 00251 void SetPattern( const ON_SimpleArray<double>& dashes); 00252 00253 /* 00254 Description: 00255 Get the line's angle, base, offset and dashes 00256 in one function call 00257 Parameters: 00258 angle - [out] angle in radians CCW from x-axis 00259 base - [out] origin of the master line 00260 offset - [out] offset for line replications 00261 dashes - [out] the dash array for the line 00262 Return: 00263 */ 00264 void GetLineData( 00265 double& angle, 00266 ON_2dPoint& base, 00267 ON_2dVector& offset, 00268 ON_SimpleArray<double>& dashes) const; 00269 00270 /* 00271 Description: 00272 Get the total length of a pattern repeat 00273 Parameters: 00274 Return: 00275 Pattern length 00276 */ 00277 double GetPatternLength() const; 00278 00279 public: 00280 double m_angle; 00281 ON_2dPoint m_base; 00282 ON_2dVector m_offset; 00283 ON_SimpleArray< double> m_dashes; 00284 }; 00285 00286 00287 00288 00289 #if defined(ON_DLL_TEMPLATE) 00290 // This stuff is here because of a limitation in the way Microsoft 00291 // handles templates and DLLs. See Microsoft's knowledge base 00292 // article ID Q168958 for details. 00293 #pragma warning( push ) 00294 #pragma warning( disable : 4231 ) 00295 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_HatchLoop*>; 00296 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_HatchLine>; 00297 #pragma warning( pop ) 00298 #endif 00299 00300 00301 /* 00302 class ON_HatchPattern 00304 Fill definition for a hatch 00305 00306 The hatch will be one of 00307 ON_Hatch::ftLines - pat file style definition 00308 ON_Hatch::ftGradient - uses a color function 00309 ON_Hatch::ftSolid - uses entity color 00310 00311 */ 00312 class ON_CLASS ON_HatchPattern : public ON_Object 00313 { 00314 ON_OBJECT_DECLARE( ON_HatchPattern); 00315 00316 public: 00317 00318 enum eFillType 00319 { 00320 ftSolid = 0, // uses entity color 00321 ftLines = 1, // pat file definition 00322 ftGradient = 2, // uses a fill color function 00323 ftLast = 3 00324 }; 00325 00326 ON_HatchPattern(); 00327 ~ON_HatchPattern(); 00328 // C++ default copy construction and operator= work fine. 00329 00330 // ON_Object overrides 00332 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00333 void Dump( ON_TextLog& ) const; // for debugging 00334 ON_BOOL32 Write( ON_BinaryArchive&) const; 00335 ON_BOOL32 Read( ON_BinaryArchive&); 00336 00337 // virtual 00338 ON_UUID ModelObjectId() const; 00339 00340 00342 // Interface 00343 00344 /* 00345 Description: 00346 Return the pattern's fill type 00347 Parameters: 00348 */ 00349 eFillType FillType() const; 00350 00351 /* 00352 Description: 00353 Set the pattern's fill type 00354 Parameters: 00355 type - [in] the new filltype 00356 */ 00357 void SetFillType( eFillType type); 00358 00359 /* 00360 Description: 00361 Set the name of the pattern 00362 Parameters: 00363 pName - [in] the new name 00364 Returns: 00365 */ 00366 void SetName( const wchar_t* pName); 00367 void SetName( const char* pName); 00368 00369 /* 00370 Description: 00371 Get the name of the pattern 00372 Parameters: 00373 string - [out] The name is returned here 00374 */ 00375 void GetName( ON_wString& string) const; 00376 00377 /* 00378 Description: 00379 Get the name of the pattern 00380 Returns: 00381 The name string 00382 */ 00383 const wchar_t* Name() const; 00384 00385 /* 00386 Description: 00387 Set the name of the pattern 00388 Parameters: 00389 pDescription - [in] the new description 00390 Returns: 00391 */ 00392 void SetDescription( const wchar_t* pDescription); 00393 void SetDescription( const char* pDescription); 00394 00395 /* 00396 Description: 00397 Get a short description of the pattern 00398 Parameters: 00399 string - [out] The string is returned here 00400 */ 00401 void GetDescription( ON_wString& string) const; 00402 00403 /* 00404 Description: 00405 Return a short text description of the pattern type 00406 Parameters: 00407 Returns: 00408 The description string 00409 */ 00410 const wchar_t* Description() const; 00411 00412 /* 00413 Description: 00414 Set the table index of the pattern 00415 Parameters: 00416 index - [in] the new index 00417 Returns: 00418 */ 00419 void SetIndex( int index); 00420 00421 /* 00422 Description: 00423 Return the table index of the pattern 00424 Parameters: 00425 Returns: 00426 The table index 00427 */ 00428 int Index() const; 00429 00430 // Interface functions for line hatches 00432 /* 00433 Description: 00434 Get the number of ON_HatchLines in the pattern 00435 Parameters: 00436 Return: 00437 number of lines 00438 */ 00439 int HatchLineCount() const; 00440 00441 /* 00442 Description: 00443 Add an ON_HatchLine to the pattern 00444 Parameters: 00445 line - [in] the line to add 00446 Return: 00447 >= 0 index of the new line 00448 -1 on failure 00449 */ 00450 int AddHatchLine( const ON_HatchLine& line); 00451 00452 /* 00453 Description: 00454 Get the ON_HatchLine at index 00455 Parameters: 00456 index - [in] Index of the line to get 00457 Return: 00458 the hatch line 00459 NULL if index is out of range 00460 */ 00461 const ON_HatchLine* HatchLine( int index) const; 00462 00463 /* 00464 Description: 00465 Remove a hatch line from the pattern 00466 Parameters: 00467 index - [in] Index of the line to remove 00468 Return: 00469 true - success 00470 false - index out of range 00471 */ 00472 bool RemoveHatchLine( int index); 00473 00474 /* 00475 Description: 00476 Remove all of the hatch line from the pattern 00477 Parameters: 00478 00479 Return: 00480 true - success 00481 false - index out of range 00482 */ 00483 void RemoveAllHatchLines(); 00484 00485 /* 00486 Description: 00487 Set all of the hatch lines at once. 00488 Existing hatchlines are deleted. 00489 Parameters: 00490 lines - [in] Array of lines to add. Lines are copied 00491 Return: 00492 number of lines added 00493 */ 00494 int SetHatchLines( const ON_ClassArray<ON_HatchLine> lines); 00495 00496 public: 00497 int m_hatchpattern_index; // Index in the hatch pattern table 00498 ON_wString m_hatchpattern_name; // String name of the pattern 00499 ON_UUID m_hatchpattern_id; 00500 00501 eFillType m_type; 00502 00503 ON_wString m_description; // String description of the pattern 00504 00505 // Represents a collection of ON_HatchLine's to make a complete pattern 00506 // This is the definition of a hatch pattern. 00507 // Simple solid line hatches with fixed angle and spacing are also 00508 // represented with this type of hatch 00509 ON_ClassArray<ON_HatchLine> m_lines; // used by line hatches 00510 }; 00511 00512 /* 00513 class ON_Hatch 00515 Represents a hatch in planar boundary loop or loops 00516 This is a 2d entity with a plane defining a local coordinate system 00517 The loops, patterns, angles, etc are all in this local coordinate system 00518 00519 The ON_Hatch object manages the plane and loop array 00520 Fill definitions are in the ON_HatchPattern or class derived from ON_HatchPattern 00521 ON_Hatch has an index to get the pattern definition from the pattern table 00522 00523 */ 00524 class ON_CLASS ON_Hatch : public ON_Geometry 00525 { 00526 ON_OBJECT_DECLARE( ON_Hatch); 00527 00528 public: 00529 // Default constructor 00530 ON_Hatch(); 00531 ON_Hatch( const ON_Hatch&); 00532 ON_Hatch& operator=(const ON_Hatch&); 00533 ~ON_Hatch(); 00534 00535 virtual ON_Hatch* DuplicateHatch() const; 00536 00537 // ON_Object overrides 00539 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00540 void Dump( ON_TextLog& ) const; // for debugging 00541 ON_BOOL32 Write( ON_BinaryArchive&) const; 00542 ON_BOOL32 Read( ON_BinaryArchive&); 00543 ON::object_type ObjectType() const; 00544 00545 // ON_Geometry overrides 00547 /* 00548 Returns the geometric dimension of the object ( usually 3) 00549 */ 00550 int Dimension() const; 00551 00552 /* 00553 Description: 00554 Get a bounding 3d WCS box of the object 00555 This is a bounding box of the boundary loops 00556 Parameters: 00557 [in/out] double* boxmin - pointer to dim doubles for min box corner 00558 [in/out] double* boxmax - pointer to dim doubles for max box corner 00559 [in] ON_BOOL32 growbox - true to grow the existing box, 00560 false ( the default) to reset the box 00561 Returns: 00562 true = Success 00563 false = Failure 00564 Remarks: 00565 */ 00566 ON_BOOL32 GetBBox( double*, double*, ON_BOOL32 = false) const; 00567 00568 /* 00569 Description: 00570 Get tight bounding box of the hatch. 00571 Parameters: 00572 tight_bbox - [in/out] tight bounding box 00573 bGrowBox -[in] (default=false) 00574 If true and the input tight_bbox is valid, then returned 00575 tight_bbox is the union of the input tight_bbox and the 00576 tight bounding box of the hatch. 00577 xform -[in] (default=NULL) 00578 If not NULL, the tight bounding box of the transformed 00579 hatch is calculated. The hatch is not modified. 00580 Returns: 00581 True if the returned tight_bbox is set to a valid 00582 bounding box. 00583 */ 00584 bool GetTightBoundingBox( 00585 ON_BoundingBox& tight_bbox, 00586 int bGrowBox = false, 00587 const ON_Xform* xform = 0 00588 ) const; 00589 00590 00591 /* 00592 Description: 00593 Transform the object by a 4x4 xform matrix 00594 00595 Parameters: 00596 [in] xform - An ON_Xform with the transformation information 00597 Returns: 00598 true = Success 00599 false = Failure 00600 Remarks: 00601 The object has been transformed when the function returns. 00602 */ 00603 ON_BOOL32 Transform( const ON_Xform&); 00604 00605 // Interface 00607 00608 /* 00609 Description: 00610 Create a hatch from input geometry and parameters 00611 Parameters: 00612 plane [I] - ON_Plane to make the hatch on 00613 loops [I] - Array of boundary loops with the outer one first 00614 pattern_index [I] - Index into the hatch table 00615 pattern_rotation [I] - ccw in radians about plane origin 00616 pattern_scale [I] - Scale factor for pattern definition 00617 Returns: 00618 true = success, false = failure 00619 */ 00620 bool Create( const ON_Plane& plane, 00621 const ON_SimpleArray<const ON_Curve*> loops, 00622 int pattern_index, 00623 double pattern_rotation, 00624 double pattern_scale); 00625 00626 /* 00627 Description: 00628 Get the plane defining the hatch's coordinate system 00629 Parameters: 00630 Returns: 00631 the plane 00632 */ 00633 const ON_Plane& Plane() const; 00634 00635 /* 00636 Description: 00637 Set the plane defining the hatch's coordinate system 00638 Parameters: 00639 plane - [in] the plane to set 00640 Returns: 00641 */ 00642 void SetPlane( const ON_Plane& plane); 00643 00644 /* 00645 Description: 00646 Gets the rotation applied to the hatch pattern 00647 when it is mapped to the hatch's plane 00648 Returns: 00649 The rotation in radians 00650 Remarks: 00651 The pattern is rotated counter-clockwise around 00652 the hatch's plane origin by this value 00653 */ 00654 double PatternRotation() const; 00655 00656 /* 00657 Description: 00658 Sets the rotation applied to the hatch pattern 00659 when it is mapped to the hatch's plane 00660 Parameters: 00661 rotation - [in] The rotation in radians 00662 Remarks: 00663 The pattern is rotated counter-clockwise around 00664 the hatch's plane origin by this value 00665 */ 00666 void SetPatternRotation( double rotation); 00667 00668 /* 00669 Description: 00670 Gets the scale applied to the hatch pattern 00671 when it is mapped to the hatch's plane 00672 Returns: 00673 The scale 00674 Remarks: 00675 The pattern is scaled around 00676 the hatch's plane origin by this value 00677 */ 00678 double PatternScale() const; 00679 00680 /* 00681 Description: 00682 Sets the scale applied to the hatch pattern 00683 when it is mapped to the hatch's plane 00684 Parameters: 00685 scale - [in] The scale 00686 Remarks: 00687 The pattern is scaled around 00688 the hatch's plane origin by this value 00689 */ 00690 void SetPatternScale( double scale); 00691 00692 /* 00693 Description: 00694 Get the number of loops used by this hatch 00695 Parameters: 00696 Returns: 00697 the number of loops 00698 */ 00699 int LoopCount() const; 00700 00701 /* 00702 Description: 00703 Add a loop to the hatch 00704 Parameters: 00705 loop - [in] the loop to add. Memory management for the loop is managed 00706 by this class. 00707 Returns: 00708 */ 00709 void AddLoop( ON_HatchLoop* loop); 00710 00711 /* 00712 Description: 00713 Insert a loop to the hatch at the specified index 00714 Parameters: 00715 index - [in] zero based index of the position where insert the loop to. 00716 loop - [in] the loop to insert. Memory management for the loop is managed 00717 by this class on success. 00718 Returns: 00719 true if success 00720 false if index is lower than 0 or greater than current loop count. 00721 */ 00722 bool InsertLoop( int index, 00723 ON_HatchLoop* loop); 00724 00725 /* 00726 Description: 00727 Remove a loop in the hatch 00728 Parameters: 00729 loop - [in] zero based index of the loop to remove. 00730 Returns: 00731 true if success 00732 */ 00733 bool RemoveLoop( int index); 00734 00735 /* 00736 Description: 00737 Get the loop at index 00738 Parameters: 00739 index - [in] which loop to get 00740 Returns: 00741 pointer to loop at index 00742 NULL if index is out of range 00743 */ 00744 const ON_HatchLoop* Loop( int index) const; 00745 00746 /* 00747 Description: 00748 Get the 3d curve corresponding to loop[index] 00749 Parameters: 00750 index - [in] which loop to get 00751 Returns: 00752 pointer to 3d curve of loop at index 00753 NULL if index is out of range or curve can't be made 00754 Caller deletes the returned curve 00755 */ 00756 ON_Curve* LoopCurve3d( int index) const; 00757 00758 /* 00759 Description: 00760 Get the index of the hatch's pattern 00761 Parameters: 00762 Returns: 00763 index of the pattern 00764 */ 00765 int PatternIndex() const; 00766 00767 /* 00768 Description: 00769 Set the index of the hatch's pattern 00770 Parameters: 00771 index - [in] pattern index to set 00772 Returns: 00773 */ 00774 void SetPatternIndex( int index); 00775 00776 // Basepoint functions added March 23, 2008 -LW 00777 /* 00778 Description: 00779 Set 2d Base point for hatch pattern alignment. 00780 Parameters: 00781 basepoint - 2d point in hatch's ECS 00782 */ 00783 void SetBasePoint(ON_2dPoint basepoint); 00784 00785 /* 00786 Description: 00787 Set 3d Base point for hatch pattern alignment. 00788 Parameters: 00789 point - 3d WCS point 00790 Remarks: 00791 Projects point to hatch's plane and sets 2d point 00792 */ 00793 void SetBasePoint(ON_3dPoint point); 00794 00795 /* 00796 Description: 00797 Return 3d WCS point that lies on hatch's plane used for pattern origin. 00798 */ 00799 ON_3dPoint BasePoint() const; 00800 00801 /* 00802 Description: 00803 Return 2d ECS point used for pattern origin. 00804 */ 00805 ON_2dPoint BasePoint2d() const; 00806 00807 /* 00808 Function added June 12 2008 LW 00809 Description: 00810 Remove all of the loops on the hatch and add the curves in 'loops' as new loops 00811 Parameters: 00812 loops - [in] An array of pointers to 2d or 3d curves 00813 If the curves are 2d, add them to the hatch directly 00814 If they are 3d, project them to the hatch's plane first 00815 Returns: 00816 true - success 00817 false - no loops in input array or an error adding them 00818 */ 00819 bool ReplaceLoops(ON_SimpleArray<const ON_Curve*> loops); 00820 00821 protected: 00822 ON_Plane m_plane; 00823 double m_pattern_scale; 00824 double m_pattern_rotation; 00825 ON_SimpleArray<ON_HatchLoop*> m_loops; 00826 int m_pattern_index; 00827 00828 // This function is temporary and will be removed next time the SDK can be modified. 00829 class ON_HatchExtra* HatchExtension(); 00830 00831 }; 00832 00833 #endif