attrmap.cpp

Go to the documentation of this file.
00001 // $Id: attrmap.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Created by MarkN 11/1/96
00099 // Implements the CCAttrMap class
00100 
00101 #include "camtypes.h"
00102 #include "attrmap.h"
00103 //#include "nodeattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "lineattr.h"
00106 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "nodedoc.h"
00110 #include "glatable.h"
00111 
00112 CC_IMPLEMENT_DYNAMIC(CCAttrMap, CCObject)
00113 
00114 /********************************************************************************************
00115 
00116 >   void CCAttrMap::DeleteAttributes()
00117 
00118     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00119     Created:    12/1/96
00120     Inputs:     
00121     Outputs:    -
00122     Returns:    -
00123     Purpose:    Deletes all the attributes within this map
00124 
00125                 NOTE: THIS CAN BE DANGEROUS.  Only delete the attributes within this map if
00126                 you know for sure that they are not being used.  This usually means only delete
00127                 if the attrs in this map are not in the tree.
00128 
00129                 The blend system generates attrs out of the tree, so they can be deleted.
00130                 NodeRenderableInk::FindAppliedAttributes() finds a list of attrs in the tree
00131                 and therefore should not be deleted via this call.
00132 
00133     SeeAlso:    CCAttrMap::Copy()
00134 
00135 ********************************************************************************************/
00136 
00137 void CCAttrMap::DeleteAttributes()
00138 {
00139     CCRuntimeClass     *pType;
00140     void               *pVal;
00141 
00142     // iterating all (key, value) pairs
00143     for( iterator Pos = GetStartPosition(); Pos != GetEndPosition(); )
00144     {
00145         // Get attr at position Pos
00146         GetNextAssoc( Pos, pType, pVal );
00147 
00148         if (pVal != NULL)
00149         {
00150             RemoveKey(pType);
00151             // Must cast to NodeAttribute before deleting, otherwise wrong destructor gets called
00152             delete (NodeAttribute*)pVal;
00153         }
00154     }
00155 }
00156 
00157 /********************************************************************************************
00158 
00159 >   CCAttrMap* CCAttrMap::Copy()
00160 
00161     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00162     Created:    12/1/96
00163     Inputs:     
00164     Outputs:    -
00165     Returns:    Ptr to a new CCAttrMap, or NULL if it fails
00166     Purpose:    Copies all the attributes within this map into a new CCAttrMap.
00167                 A ptr to the new map is returned, or NULL if it fails
00168 
00169                 The new map contains a list of attrs that are not attached in the tree. If the
00170                 attrs are not needed or used (e.g. not inserted into the tree) make sure you
00171                 delete the attrs via DeleteAttributes() before deleting the CCAttrMap, otherwise
00172                 memory leaks will occur.
00173 
00174     SeeAlso:    CCAttrMap::DeleteAttributes()
00175 
00176 ********************************************************************************************/
00177 
00178 CCAttrMap* CCAttrMap::Copy()
00179 {
00180     CCAttrMap          *pNewAttrMap = new CCAttrMap( GetCount() );
00181     if( pNewAttrMap != NULL )
00182     {
00183         // iterating all (key, value) pairs
00184         for( iterator Pos = GetStartPosition(); Pos != GetEndPosition(); )
00185         {
00186             CCRuntimeClass *pType;
00187             void       *pVal;
00188             GetNextAssoc( Pos, pType, pVal );
00189 
00190             // Get the attribute value of this attribute
00191             NodeAttribute* pAttr = (NodeAttribute*)pVal;
00192 
00193             // Copy the attribute
00194             NodeAttribute* pNewAttr = (NodeAttribute*) (pAttr->SimpleCopy());
00195 
00196             // Stick the new attr into the new attr map
00197             if (pNewAttr != NULL)
00198                 pNewAttrMap->SetAt(pNewAttr->GetAttributeType(),pNewAttr);
00199         }
00200     }
00201 
00202     pNewAttrMap->attrMapCreator = attrMapCreator;
00203 
00204     return pNewAttrMap;
00205 }
00206 
00207 /********************************************************************************************
00208 
00209 >   static CCAttrMap* CCAttrMap::MakeAppliedAttrMap(NodeRenderableInk* pInkNode,
00210                                                     BOOL ExcludeIndirectlyAppliedGLAs = TRUE,
00211                                                     BOOL bStrictEffectStatus = TRUE)
00212 
00213     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00214     Created:    15/1/96
00215     Inputs:     pInkNode = ptr to an ink node
00216                 ExcludeIndirectlyAppliedGLAs - whether they should be excluded from this attrmap
00217     Outputs:    -
00218     Returns:    Ptr to a new CCAttrMap, or NULL if it fails
00219     Purpose:    This creates a new CCAttrMap and fills it with ptrs to applied attrs of pInkNode.
00220 
00221                 pInkNode must be a node that is inserted in the tree, and is not hidden.
00222 
00223                 It is the caller's responsibility to delete the returned CCAttrMap.
00224                 Note: As the map contains ptrs to attrs in the tree.  Do not call DeleteAttributes()
00225                 on the returned CCAttrMap
00226 
00227     SeeAlso:    CCAttrMap::Copy()
00228 
00229 ********************************************************************************************/
00230 
00231 CCAttrMap* CCAttrMap::MakeAppliedAttrMap(NodeRenderableInk* pInkNode,
00232                                          BOOL ExcludeIndirectlyAppliedGLAs,
00233                                          BOOL bStrictEffectStatus)
00234 {
00235     ERROR2IF(pInkNode == NULL,NULL,"pInkNode is NULL");
00236     // ERROR2IF(pInkNode->FindParent() == NULL,NULL,"pInkNode has no parent");
00237 
00238     CCAttrMap* pAttrMap = new CCAttrMap(30);
00239     if (pAttrMap != NULL)
00240     {
00241         if (!pInkNode->FindAppliedAttributes(pAttrMap,
00242                                              5000,
00243                                              NULL,
00244                                              ExcludeIndirectlyAppliedGLAs,
00245                                              bStrictEffectStatus))
00246         {
00247             delete pAttrMap;
00248             pAttrMap = NULL;
00249         }
00250         else
00251         {
00252             pAttrMap->attrMapCreator = (Node*) pInkNode;
00253         }
00254     }
00255 
00256     return pAttrMap;
00257 }
00258 
00259 /********************************************************************************************
00260 
00261 >   void CCAttrMap::Transform(TransformBase& Trans)
00262 
00263     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00264     Created:    30/4/99
00265     Inputs:     Trans
00266     Outputs:    -
00267     Returns:    -
00268     Purpose:    Applies the given transform to all the attrs in this map
00269     SeeAlso:    -
00270 
00271 ********************************************************************************************/
00272 
00273 void CCAttrMap::Transform(TransformBase& Trans)
00274 {
00275     CCRuntimeClass     *pType;
00276     void               *pVal;
00277     for( iterator Pos = GetStartPosition(); Pos != GetEndPosition(); )
00278     {
00279         GetNextAssoc(Pos,pType,pVal);
00280         if (pVal != NULL)
00281         {
00282             NodeAttribute* pNodeAttr = (NodeAttribute *)pVal;
00283             pNodeAttr->Transform(Trans);
00284         }
00285     }
00286 }
00287 
00288 /********************************************************************************************
00289 
00290 >   void CCAttrMap::TransformForBrush(TransformBase& Trans)
00291 
00292     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00293     Created:    30/4/99
00294     Inputs:     Trans
00295     Outputs:    -
00296     Returns:    -
00297     Purpose:    Applies the given transform to all the attrs in this map that need to be rendered
00298                 at every step of a brush or a blend.  This allows us to tile as things such as bitmap
00299                 fills remain in the same place always
00300     SeeAlso:    -
00301 
00302 ********************************************************************************************/
00303 
00304 void CCAttrMap::TransformForBrush(TransformBase& Trans)
00305 {
00306     CCRuntimeClass     *pType;
00307     void               *pVal;
00308     for( iterator Pos = GetStartPosition(); Pos != GetEndPosition(); )
00309     {
00310         GetNextAssoc(Pos,pType,pVal);
00311         if (pVal != NULL)
00312         {
00313             NodeAttribute* pNodeAttr = (NodeAttribute *)pVal;
00314             
00315             // check that we are not about to set line width to zero
00316             if( pNodeAttr->IsALineWidthAttr() && Trans.TransLines != FALSE )
00317             {
00318                 double Test =  Trans.GetScalar().MakeDouble() * (double)((AttrLineWidth*)pNodeAttr)->Value.LineWidth;
00319         //      TRACEUSER( "Diccon", _T("Scale line width by %f\n"), Test);
00320                 if (Test <= 1.0)
00321                 {
00322                 //  TRACEUSER( "Diccon", _T("Setting line width scaling OFF\n"));
00323                     Trans.TransLines = FALSE;
00324                 }
00325             }
00326 
00327             if (pNodeAttr->NeedsToRenderAtEachBrushStroke())
00328                 pNodeAttr->Transform(Trans);
00329         }
00330     }
00331 }
00332 
00333 /********************************************************************************************
00334 
00335 >   void CCAttrMap::TransformForBrush(TransformBase& Trans)
00336 
00337     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00338     Created:    30/4/99
00339     Inputs:     Trans
00340     Outputs:    -
00341     Returns:    -
00342     Purpose:    Applies the transform to all the attributes that do not have to render for each
00343                 brush step.
00344     SeeAlso:    -
00345 
00346 ********************************************************************************************/
00347 
00348 void CCAttrMap::TransformBrushFills(TransformBase& Trans)
00349 {
00350     CCRuntimeClass     *pType;
00351     void               *pVal;
00352     for( iterator Pos = GetStartPosition(); Pos != GetEndPosition(); )
00353     {
00354         GetNextAssoc(Pos,pType,pVal);
00355         if (pVal != NULL)
00356         {
00357             NodeAttribute* pNodeAttr = (NodeAttribute *)pVal;
00358             
00359             // check that we are not about to set line width to zero
00360             if( pNodeAttr->IsALineWidthAttr() && Trans.TransLines != FALSE )
00361             {
00362                 INT32 Test = labs( INT32(Trans.GetScalar().MakeDouble() * ((AttrLineWidth*)pNodeAttr)->Value.LineWidth) );      
00363                 if (Test <= 10)
00364                     Trans.TransLines = FALSE;
00365             }
00366 
00367             if (!pNodeAttr->NeedsToRenderAtEachBrushStroke())
00368                 pNodeAttr->Transform(Trans);
00369         }
00370     }
00371 
00372 
00373 }
00374 
00375 
00376 /********************************************************************************************
00377 
00378 >   BOOL CCAttrMap::WillScaleLineWidthToZero(TransformBase& Trans)
00379 
00380     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    30/4/99
00382     Inputs:     Trans - the transformation we wish to test
00383     Outputs:    -
00384     Returns:    TRUE if this transformation will scale the line width in this map to zero or not
00385     Purpose:    As above, this can be useful information as if we pass GDraw a line width of zero
00386                 it reverts to zero quality.
00387     SeeAlso:    -
00388 
00389 ********************************************************************************************/
00390 
00391 BOOL CCAttrMap::WillScaleLineWidthToZero(TransformBase& Trans)
00392 {
00393     // first look up the line width
00394     AttrLineWidth* pLineWidth = NULL;
00395     Lookup( CC_RUNTIME_CLASS(AttrLineWidth), (void*&)pLineWidth );
00396     
00397     // if we don't have a line width then we're obviously not going to scale it to zero
00398     if (pLineWidth == NULL)
00399         return FALSE;
00400 
00401     // also look up the stroke colour, if it is fully transparent then the line
00402     // is invisible anyway
00403     AttrStrokeColour* pStrokeCol = NULL;
00404     Lookup( CC_RUNTIME_CLASS(AttrStrokeColour), (void*&)pStrokeCol );
00405     if (pStrokeCol && pStrokeCol->Value.Colour.IsTransparent())
00406         return FALSE;
00407 
00408     double ScaleFactor = Trans.GetScalar().MakeDouble();
00409     INT32 ScaleVal = (INT32)(ScaleFactor * (double)pLineWidth->Value.LineWidth);
00410     if (ScaleVal < 1)
00411         return TRUE;
00412 
00413     return FALSE;
00414 }
00415 
00416 /********************************************************************************************
00417 
00418 >   void CCAttrMap::Render(RenderRegion * pRegion, BOOL RenderOffscreenAttributes = TRUE)
00419 
00420     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00421     Created:    30/4/99
00422     Inputs:     pRegion                     render-region to render into.
00423                 RenderOffscreenAttributes   whether or not to render offscreen attributes,
00424                                             eg feathers.
00425     Outputs:    -
00426     Returns:    -
00427     Purpose:    Renders the attribute map into the given render region
00428 
00429     Notes:      Karim 15/11/2000
00430                 Modified so that I can render an attribute map *without*
00431                 rendering any offscreen attributes contained therein.
00432 
00433     SeeAlso:    -
00434 
00435 ********************************************************************************************/
00436 void CCAttrMap::Render(RenderRegion * pRegion, BOOL RenderOffscreenAttributes)
00437 {
00438     // OK, we have found the full quota of attributes.  Now render them all.
00439     iterator            pos = GetStartPosition();
00440     while( pos != GetEndPosition() )
00441     {
00442         CCRuntimeClass *pKey;
00443         void           *pVal;
00444         GetNextAssoc( pos, pKey, pVal );
00445 
00446         NodeAttribute* pAttr = (NodeAttribute*)pVal;
00447 
00448         if ( pAttr->CanBeAppliedToObject() &&
00449              pAttr->RenderSubtree(pRegion)==SUBTREE_ROOTONLY )
00450         {
00451             // render all attributes, unless we've been specifically asked
00452             // not to render offscreen attributes.
00453             if (RenderOffscreenAttributes || !pAttr->IsAnOffscreenAttribute())
00454                 pAttr->Render(pRegion);
00455         }
00456     }
00457 }
00458 
00459 /********************************************************************************************
00460 
00461 >   void CCAttrMap::BuildListOfAttributes(List * pList)
00462 
00463     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00464     Created:    30/4/99
00465     Inputs:     The list to use
00466     Outputs:    -
00467     Returns:    -
00468     Purpose:    Builds a list of NodeListItems of all the attributes in this attribute map
00469     Notes:      Includes all attributes - even those which can't be applied to objects
00470                 Use CanBeAppliedToObject to test
00471     SeeAlso:    -
00472 
00473 ********************************************************************************************/
00474 void CCAttrMap::BuildListOfAttributes(List * pList)
00475 {
00476     iterator            pos = GetStartPosition();
00477 
00478     NodeListItem       *pItem = NULL;
00479 
00480     while( pos != GetEndPosition() )
00481     {
00482         CCRuntimeClass *pKey;
00483         void           *pVal;
00484         GetNextAssoc( pos, pKey, pVal );
00485 
00486         pItem = new NodeListItem((NodeAttribute *)pVal);
00487 
00488         pList->AddTail(pItem);
00489     }
00490 }
00491 
00492 /********************************************************************************************
00493 
00494 >   NodeAttribute* CCAttrMap::FindAttribute(CCRuntimeClass* Class)
00495 
00496     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00497     Created:    15/6/2000
00498     Inputs:     The attribute type that we are to find.
00499     Outputs:    The attribute that matches this attribute type
00500     Returns:    -
00501     Purpose:    Call to retrieve a ptr to the attribute of the supplied type
00502     Notes:      
00503     SeeAlso:    -
00504 
00505 ********************************************************************************************/
00506 
00507 NodeAttribute* CCAttrMap::FindAttribute(NodeAttribute *pTypeAttr)//CCRuntimeClass* Class)
00508 {
00509     void* ptrToAttr = NULL;
00510 
00511     if( Lookup( pTypeAttr->GetAttributeType(), ptrToAttr ) )
00512     {
00513         return (NodeAttribute *)ptrToAttr;
00514     }
00515     
00516     return (NULL);
00517 }
00518 
00519 /********************************************************************************************
00520 
00521 >   NodeAttribute * CCAttrMap::ReplaceAttribute(NodeAttribute *pNewAttr)
00522 
00523     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00524     Created:    10/12/99
00525     Inputs:     The attribute to replace
00526     Outputs:    The old attribute - in case it needs deleting
00527     Returns:    -
00528     Purpose:    Directly replaces the attribute in this map with the given one
00529     Notes:      
00530     SeeAlso:    -
00531 
00532 ********************************************************************************************/
00533 
00534 NodeAttribute * CCAttrMap::ReplaceAttribute(NodeAttribute *pNewAttr)
00535 {
00536     void* pOldAttr = NULL;
00537     if( Lookup( pNewAttr->GetAttributeType(), pOldAttr ) )
00538     {
00539         // We need to Remove and Delete the existing Stroke Colour Attr
00540         RemoveKey( pNewAttr->GetAttributeType() );
00541     }
00542     
00543     // Add the new attr into the attr map
00544     SetAt( pNewAttr->GetAttributeType(), (void*)pNewAttr ); 
00545 
00546     return (NodeAttribute *)pOldAttr;
00547 }
00548 
00549 
00550 
00551 
00552 /********************************************************************************************
00553 
00554 >   void CCAttrMap::RemoveAttribute(CCRuntimeClass* pAttrClass)
00555 
00556     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00557     Created:    04/11/2005
00558     Inputs:     The attribute class to remove
00559     Outputs:    -
00560     Returns:    -
00561     Purpose:    Removes and Deletes the given attribute type
00562     Notes:      
00563     SeeAlso:    -
00564 
00565 ********************************************************************************************/
00566 
00567 void CCAttrMap::RemoveAttribute(CCRuntimeClass* pAttrClass)
00568 {
00569     NodeAttribute* pOldAttr = NULL;
00570     if( Lookup( pAttrClass, (void*&)pOldAttr ) )
00571     {
00572         if (pOldAttr)
00573             delete pOldAttr;
00574 
00575         // We need to Remove and Delete the existing Stroke Colour Attr
00576         RemoveKey( pAttrClass );
00577     }
00578 }
00579 
00580 
00581 
00582 
00583 /********************************************************************************************
00584 
00585 >   static CCAttrMap * CCAttrMap::MakeAttrMapFromRenderRegion(RenderRegion * pRegion)
00586 
00587     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00588     Created:    24/2/2000
00589     Inputs:     The render region to get the attribute map from
00590     Outputs:    An attribute map (copied) from the render region
00591     Returns:    -
00592     Purpose:    Makes an attribute out of the render region's current attribute state
00593     Notes:      You MUST call DeleteAttributes afterwards to release memory - delete is
00594                 not sufficient
00595     SeeAlso:    -
00596 
00597 ********************************************************************************************/
00598 CCAttrMap * CCAttrMap::MakeAttrMapFromRenderRegion(RenderRegion * pRegion)
00599 {
00600     CCAttrMap * pMap = new CCAttrMap;
00601     ENSURE(pMap,"No mem for attrmap");
00602     if(!pMap)
00603         return NULL;
00604 
00605     // let's get every attribute in the render region
00606     AttributeValue * pAttrVal = NULL;
00607     NodeAttribute * pNewAttr = NULL;
00608 
00609     for (UINT32 i = 0; i < ATTR_FIRST_FREE_ID; i++)
00610     {
00611         pAttrVal = pRegion->GetCurrentAttribute(i);
00612 
00613         // make a new node out of this attribute value
00614         pNewAttr = pAttrVal->MakeNode();
00615         
00616         // Karim 12/04/2000
00617         // AttributeValues _do_not_have_to_have_ a corresponding NodeAttribute,
00618         // so can we please *check* that MakeNode didn't just return NULL!
00619         if (pNewAttr != NULL)
00620         {
00621             if(!pNewAttr->IsLinkedToNodeGeometry())
00622                 pMap->SetAt(pNewAttr->GetAttributeType(),pNewAttr);
00623             else
00624             {
00625                 delete pNewAttr;
00626                 pNewAttr = AttributeManager::GetDefaultAttribute((AttrIndex) i);
00627                 if(pNewAttr)
00628                 {
00629                     ENSURE(pNewAttr->IsLinkedToNodeGeometry(),"Incorrect NodeAttribute returned by GetDefaultAttribute");
00630                     pMap->SetAt(pNewAttr->GetAttributeType(), pNewAttr);
00631                 }
00632                 else
00633                     return NULL;
00634             }
00635         }
00636     }
00637 
00638     pMap->attrMapCreator = NULL;
00639 
00640     return pMap;
00641 }
00642 
00643 void CCAttrMap::ApplyAttributesToNode(NodeRenderableInk * pInk)
00644 {
00645     iterator            pos = GetStartPosition();
00646 
00647     while( pos != GetEndPosition() )
00648     {
00649         CCRuntimeClass *pKey;
00650         void           *pVal;
00651         GetNextAssoc(pos, pKey, pVal);
00652 
00653         NodeAttribute * pAttr = (NodeAttribute *)pVal;
00654 
00655         // copy the attribute
00656         if( pAttr->CanBeAppliedToObject() )
00657         {
00658             NodeAttribute * pAttrCopy = NULL;
00659             pAttr->NodeCopy((Node **)(&pAttrCopy));
00660             
00661             pAttrCopy->AttachNode(pInk, LASTCHILD);
00662 
00663             // nb now that GLAs have an independent flag to indicate when
00664             // they are copied from the default, it is safe to fix linkages
00665             // this ensures that GLA defaults get copied when BlendRefs are
00666             // made from complex nodes, and that they are found when MakeAppliedAttributes
00667             // calls FindAppliedAttributes on the unattached subtree
00668             // TODO??
00669             // What about just copying compound node's Parent pointers to 
00670             // pseudo attach the tree, rather than copying applied attrs to unattached tree
00671             // Just need to watch when deleting that it doesn't do anything to the
00672             // parents pointers - which it shouldn't surely?
00673             pAttrCopy->LinkToGeometry(pInk);
00674         }
00675     }
00676 }
00677 
00678 // Required for all GLA's
00679 // NB must only be called on attrmaps with copied attributes
00680 // DO NOT CALL on maps with 'live' attributes - ie pointers to attrs in the tree
00681 // (eg a mpa made by MakeAppliedAttrMap(pInk))
00682 void CCAttrMap::PostBlendInit(Path* pPath, CCRuntimeClass* pCreatorClass)
00683 {
00684     INT32 curr = 0;
00685 
00686     // NB this function is called on a Blended attr map
00687     // The Blend() function should return false if it doesn't want to be in the blended attr map
00688     // ie default GLAs shouldn't be in here!
00689 
00690     do
00691     {
00692         CCRuntimeClass *pType = (CCRuntimeClass *)GeometryLinkedAttributeClasses[curr];
00693         void           *pVal;
00694                 
00695         if( Lookup( pType, pVal ) )
00696         {
00697             if (pVal != NULL)
00698             {
00699                 NodeAttribute * pAttr = (NodeAttribute *)pVal;
00700 
00701                 // call the attributes routine to initialise itself
00702                 if(!pAttr->PostDynCreateInit(this, pPath, pCreatorClass))
00703                 {
00704                     // make sure the node is not going to try and render itself
00705                     TRACEUSER( "Ilan", wxT("Dynamically created attribute failed to post init itself. Removing attribute from map.\n") );
00706                     // NB map must contain copied attrs
00707                     RemoveKey( pType );
00708                     // Must cast to NodeAttribute before deleting, otherwise wrong destructor gets called
00709                     delete (NodeAttribute*)pVal;
00710                 }
00711             }
00712         }
00713 
00714         curr++;
00715     }
00716     while(curr<NumGLAs);
00717 }
00718 
00719 // Required for all GLA's
00720 void CCAttrMap::PostBlendDeinit()
00721 {
00722     INT32 curr = 0;
00723 
00724     do
00725     {
00726         CCRuntimeClass *pType = (CCRuntimeClass *)GeometryLinkedAttributeClasses[curr];
00727         void           *pVal;
00728                 
00729         if( Lookup( pType, pVal ) )
00730         {
00731             if (pVal != NULL)
00732             {
00733                 NodeAttribute * pAttr = (NodeAttribute *)pVal;
00734 
00735                 pAttr->PostDynCreateDeInit();
00736             }
00737         }
00738 
00739         curr++;
00740     }
00741     while(curr<NumGLAs);
00742 }
00743 
00744 
00745 void CCAttrMap::AttachGeometryLinkedAttrs(Node* pContext)
00746 {
00747     INT32 curr = 0;
00748 
00749     do
00750     {
00751         CCRuntimeClass *pType = (CCRuntimeClass *)GeometryLinkedAttributeClasses[curr];
00752         void           *pVal;
00753                 
00754         if (Lookup(pType,pVal))
00755         {
00756             if (pVal != NULL)
00757             {
00758                 ((NodeAttribute*)pVal)->LinkToGeometry(pContext);
00759             }
00760         }
00761 
00762         curr++;
00763     }
00764     while(curr<NumGLAs);
00765 }
00766 
00767 void CCAttrMap::RemoveGeometryLinkedAttrs()
00768 {
00769     INT32 curr = 0;
00770 
00771     do
00772     {
00773         CCRuntimeClass *pType = (CCRuntimeClass *)GeometryLinkedAttributeClasses[curr];
00774         void           *pVal;
00775                 
00776         if( Lookup( pType, pVal ) )
00777         {
00778             if (pVal != NULL)
00779             {
00780                 RemoveKey( pType );
00781                 delete (NodeAttribute*)pVal;
00782             }
00783         }
00784 
00785         curr++;
00786     }
00787     while(curr<NumGLAs);
00788 }
00789 
00790 
00791 
00792 /********************************************************************************************
00793 
00794 >   BOOL CCAttrMap::IsSeeThrough()
00795 
00796     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00797     Created:    19/02/2001
00798 
00799     Returns:    TRUE if at least one of our attrs IsSeeThrough(),
00800                 FALSE otherwise.
00801 
00802     Purpose:    Test each of the attributes in this map for see-through-ness.
00803                 This is not the same as transparency - what it means is: if I draw something
00804                 in white, then draw its outline as retrieved from PathBecomeA in black over
00805                 the top, will I still be able to see white bits?
00806                 IsSeeThrough() therefore depends partly on the implementation of PathBecomeA.
00807 
00808                 Examples:
00809                     Transparency is always see-through unless it is a zero transparency.
00810                     Line width is not see through - PathBecomeA can cope with this attr.
00811                     Fill colour is not see-through unless it is COLOUR_NONE.
00812                     Brush attrs are normally see-through, as PathBecomeA ignores them.
00813 
00814     See Also:   NodeRenderableInk::IsSeeThrough()
00815 
00816 ********************************************************************************************/
00817 BOOL CCAttrMap::IsSeeThrough()
00818 {
00819     CCRuntimeClass     *pKey;
00820     void               *pVal;
00821     BOOL                bIsSeeThrough = FALSE;
00822 
00823     for ( iterator  pos = GetStartPosition();
00824                     pos != GetEndPosition() && !bIsSeeThrough;  )
00825     {
00826         GetNextAssoc(pos, pKey, pVal);
00827         NodeAttribute* pAttr = (NodeAttribute*)pVal;
00828 
00829         bIsSeeThrough = pAttr->IsSeeThrough(FALSE);
00830     }
00831 
00832     return bIsSeeThrough;
00833 }

Generated on Sat Nov 10 03:44:14 2007 for Camelot by  doxygen 1.4.4