linedef.cpp

Go to the documentation of this file.
00001 // $Id: linedef.cpp 1735 2006-09-04 10:03:55Z luke $
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 
00099 // The line definition class implementation.  An abstract base class from which to
00100 // derive the definitions of things like strokes, brushes.
00101 
00102 #include "camtypes.h"
00103 #include "linedef.h"
00104 #include "colormgr.h"
00105 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 
00107 CC_IMPLEMENT_DYNAMIC(LineDefinition, CCObject)
00108 
00109 
00110 
00111 /********************************************************************************************
00112 
00113 >   LineDefinition::LineDefinition()
00114 
00115     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00116     Created:    27/2/97
00117 
00118     Purpose:    default constructor, please don't use it though, i am only keeping it around so 
00119                 I can integrate the StrokeDefinition stuff
00120 
00121 ********************************************************************************************/
00122 
00123 LineDefinition::LineDefinition()
00124 {
00125     // set to NULL or else CascadeDelete fails in the destructor
00126     m_pTree = NULL;
00127 }
00128 
00129 /********************************************************************************************
00130 
00131 >   LineDefinition::LineDefinition(Node *pLineTree);
00132 
00133     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00134     Created:    27/2/97
00135 
00136     Inputs:     pLineTree - A pointer to a Spread node which is the root of a clipart
00137                               subtree which should be used for this Line definition. It
00138                               must obey these rules:
00139                                 * It must be a Spread
00140                                 * It must not be linked into any other parent tree structure
00141                                 * It should contain at least one path node (or else the Line
00142                                   will appear "blank"). You should do Make Shapes on the 
00143                                   subtree so that text, blends, quickshapes, etc are all in
00144                                   path form
00145                                 * It should be attribute complete, or close thereto
00146 
00147     Purpose:    Constructor
00148 
00149     SeeAlso:    LineComponent::AddNewLine
00150 
00151 ********************************************************************************************/
00152 
00153 LineDefinition::LineDefinition(Node *pLineTree)
00154 {
00155     ERROR3IF(pLineTree == NULL, "Illegal NULL param");
00156     ERROR3IF(!pLineTree->IsSpread(), "LineDefinitions must begin with a Spread (for now, at least)");
00157     ERROR3IF(pLineTree->FindParent() != NULL, "Line Definition looks like it's linked into a tree!");
00158 
00159     m_pTree   = pLineTree;
00160 
00161     // Check the subtree to see if it contains any transparency
00162     m_bNeedsTrans = m_pTree->ChildrenNeedTransparency();
00163 
00164     IOStore = 0;
00165 
00166     m_Name = TEXT("Custom line");
00167 
00168     m_bOverridesFill  = FALSE;
00169     m_bOverridesTrans = FALSE;
00170 }
00171 
00172 
00173 
00174 /********************************************************************************************
00175 
00176 >   LineDefinition::~LineDefinition()
00177 
00178     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00179     Created:    27/2/97
00180 
00181     Purpose:    Destructor
00182 
00183 ********************************************************************************************/
00184 
00185 LineDefinition::~LineDefinition()
00186 {
00187     if (m_pTree != NULL)
00188     {
00189         m_pTree->CascadeDelete();
00190         delete m_pTree;
00191     }
00192 }
00193 
00194 
00195 
00196 /********************************************************************************************
00197 
00198 >   void LineDefinition::SetLineName(StringBase *pName)
00199 
00200     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00201     Created:    5/3/97
00202 
00203     Purpose:    Sets the name text string for this Line
00204 
00205 ********************************************************************************************/
00206 
00207 void LineDefinition::SetLineName(StringBase *pName)
00208 {
00209     ERROR3IF(pName == NULL, "Illegal NULL param");
00210 
00211     pName->Left(&m_Name, 31);
00212 }
00213 
00214 
00215 
00216 /********************************************************************************************
00217 
00218 >   virtual BOOL LineDefinition::NeedsTransparency() const
00219 
00220     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00221     Created:    4/3/97
00222 
00223     Returns:    TRUE if this Line needs transparency in order to render
00224 
00225     Purpose:    Determine if this Line needs transparency in order to render.
00226 
00227 ********************************************************************************************/
00228 
00229 BOOL LineDefinition::NeedsTransparency() const
00230 {
00231     return(m_bNeedsTrans);
00232 }
00233 
00234 
00235 /********************************************************************************************
00236 
00237 >   static void LineDefinition::ConvertIndexedColours(Node* pRoot) 
00238 
00239     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    4/3/97
00241     Inputs :    pRoot - the root of the subtree that is about to passed in to create a linedef
00242                 Note that this node must actually be a SPREAD, as that is what we expect
00243     Ouputs:     pSpread with all its indexed colours converted to local doccolours
00244     Returns:    -
00245 
00246     Purpose:    To convert all the colours in the subtree that we wish to use to make a 
00247                 brush definition
00248 ********************************************************************************************/
00249 
00250 void LineDefinition::ConvertIndexedColours(Spread* pRoot)
00251 {
00252     if (pRoot == NULL)
00253     {
00254         ERROR3("Spread is NULL");
00255         return;
00256     }
00257     // start at the layer
00258     Node* pNode = pRoot->FindFirstChild();
00259     pNode = pNode->FindFirstChild();
00260 
00261     // traverse across the layer
00262     while (pNode != NULL)
00263     {
00264         // search depth first as we may have a group
00265         Node *pCurNode = pNode->FindFirstDepthFirst();
00266         Node *pNextNode;
00267 
00268         while (pCurNode !=NULL)
00269         {
00270             // We may be about to chop this node out of the tree, so get the next node now
00271             pNextNode = pCurNode->FindNextDepthFirst(pNode);
00272     
00273             // Use to scan the colour fields of the attribute.
00274             if (pCurNode->IsAnAttribute())
00275             {
00276                 UINT32 Context = 0;
00277                 NodeAttribute *pNodeAttr = (NodeAttribute *) pCurNode;
00278 
00279                 // Get the next colour field from the attribute
00280                 DocColour *pColour = pNodeAttr->EnumerateColourFields(Context++);
00281                 
00282                 while (pColour != NULL)
00283                 {
00284                     // For each colour field, make sure the colour is a local DocColour so that
00285                     // the sub-tree is entirely stand-alone
00286                     IndexedColour* pIndexCol = pColour->FindParentIndexedColour();
00287                     if (pIndexCol != NULL)
00288                     {
00289                         ColourGeneric ColDef;
00290                         ColourContext *cc = ColourManager::GetColourContext(pColour->GetColourModel());
00291                         ERROR3IF(cc == NULL, "Can't find colour context?!");
00292 
00293                         // Get the IndexedColour definition as a standalone colour definition
00294                         cc->ConvertColour(pIndexCol, &ColDef);
00295 
00296                         // Make the DocColour into a simple standalone "lookalike" of the parent colour
00297                         *pColour = DocColour(pColour->GetColourModel(), &ColDef);
00298 
00299                         // if the parent colour was named then set the reserved flag
00300                         if (pIndexCol->IsNamed())
00301                             pColour->SetReservedFlag(COL_NAMED);
00302                     }
00303                         pColour = pNodeAttr->EnumerateColourFields(Context++);
00304                 }
00305             }
00306             pCurNode = pNextNode;
00307         }
00308         
00309         pNode = pNode->FindNext(CC_RUNTIME_CLASS(NodeRenderableInk));
00310     }
00311 }

Generated on Sat Nov 10 03:45:38 2007 for Camelot by  doxygen 1.4.4