//
#ifndef __NOTESTD_H
#define __NOTESTD_H
//
//  (C) Copyright 1993-2007 by Autodesk, Inc.  All rights reserved.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//

#ifndef __ACMDEF_H
#error include 'acmdef.h' before including this file
#endif
#ifndef __SYMSTD_H
#error include 'symStd.h' before including this file
#endif

class AcmSymbol;
class AcmSymbolStd;
class AmdtNoteStdImp;
class AmdtNoteTemplate;
class AmdtNoteTemplateType;
class AmdtCNote;

class DllImpExp AmdtNoteStd : public AcmSymbolStd
{
  friend class AcmSymbbInternals;
  friend class AmdtNoteStdImp;
public:
  ACRX_DECLARE_MEMBERS(AmdtNoteStd);
  virtual ~AmdtNoteStd();

  // attachment point for the leader. Left/Right side is recognized by the symbol's
  // orientation varible
  enum attachPoint {
    // kNopoint is used for older note symbols. Setting/changing the attachment point
    // to kNoPoint will have no effect on the mText's location() and attachment() settings
    kNoPoint = 0,
    kTopText, // with overline
    kTopTopLine,
    kMiddleTopLine,
    kBottomTopLine,
    kMiddleText,
    kTopBottomLine,
    kMiddleBottomLine,
    kBottomBottomLine,
    kBottomText, // with underline    
    kTopLineRefLine,
    kUnderlineAllText,
  };
  
  enum textAlignment {
    kLeft = 0,
    kCenter,
    kRight,
  };

  // returns standard's default attachment point
  virtual AmdtNoteStd::attachPoint defaultAttachPoint() const = 0;

  // set / get methods for note data
  // gets the data for template with given name and type
  bool getTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, 
                   LPCTSTR& value) const;

  // adds new template to existing group with groupName. If such a group doesn't exists
  // and allowNewGroup == true, creates new group with new template, otherwise returns false
  bool addTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, 
                   LPCTSTR value, /*const AcDbObjectId& style,*/ const bool allowNewGroup = true);

  bool delTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName);
  void delAllTemplates(const bool delGroups = false);
  bool renameTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR oldTempName, LPCTSTR tempName);

  // changes the value of template and resets the dim style ids.
  // be VERY carefull if you try to set updateDimStyles to false! This bool was added to enable
  // some performance, but be sure that when you are setting the final value, you allow
  // the template to update dim styles.
  bool changeValue(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, LPCTSTR newValue, bool updateDimStyles = true);

  // methods for iterating through the templates.
  // sets up the feature type(s) you are interested in. In the next methods,
  // if the onlyCompatible boolean is set to true, this type is compared with the
  // group's type and only the compatible ones are taken into account.
  // To reset the condition to allow all groups, use an array with zero logical length
  // as an argument.
  void setCompatibilityCondition(const AcArray<Adesk::Int32>& type);

  // number of template groups that the standard actually holds
  int numGroups(const bool onlyCompatible = false) const;

  // returns the type and name of the index-th group
  bool getGroup(const int index, AcArray<Adesk::Int32>& type, CString& name, 
                const bool onlyCompatible = false) const;

  // returns all templates for the group with given type
  bool getAllTemplates(const AcArray<Adesk::Int32>& groupType, AcArray<LPCTSTR>& names, 
                       AcArray<LPCTSTR>& values) const;

  bool setDefaultTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, bool isSetDefault=true);

  // method to distinguish the type of features a symbol is attached to:
  AcArray<Adesk::Int32> featTypes(const AcmSymbol* pSym) const;

  virtual Adesk::Boolean setFactoryDefaults();
  virtual Acm::ErrorStatus getDescription(CString& desc,
                                          CBitmap*& pBmpLoaded,
                                          CBitmap*& pBmpReg,
                                          Adesk::Boolean& enablePref) const;

  virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* filer);
  virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* filer) const;

  virtual Acad::ErrorStatus subClose();

  virtual void getSubEnts(const AmdtCNote* pSymb,AcmCAuxEntArray& subents) const;
    
  AmdtNoteStd::attachPoint mostRecentAttachPoint() const;  
  void setMostRecentAttachPoint(const AmdtNoteStd::attachPoint & point);

  virtual Adesk::Boolean alwaysLeftTextAlign() const;
  
  virtual void updateMTextLoc(const AmdtCNote* pSymb, AcDbMText & MText, int iIndex = 0) const;

  bool landing() const;
  void setLanding (bool islanding);

  AmdtNoteStd::attachPoint leaderAttachPoint() const;
  void setLeaderAttachPoint(const AmdtNoteStd::attachPoint point);

  // Set default text and leader settings
  void setDefaultLandingAndAttachPoint();
  virtual bool isMultiBranchEnabled() const;  

protected:
  AmdtNoteStd();
  
  virtual Acad::ErrorStatus subGetClassID(CLSID* pClsid) const;
  
  void getMTextLines(const AmdtCNote* pSymb, CStringArray & lines) const;

  // support for group management:
  bool addGroup(const AcArray<Adesk::Int32> type, CString& name);

private:
  AmdtNoteStdImp* mpImp;
  
  // we don't have to serialize this, it will make a copy in updateMTextLoc()
  mutable AcDbMText mMText;
  mutable AcDbMText mMTextMax;
  mutable AcDbMText mMTextPrev;
};
MAKE_ACDBOPENOBJECT_FUNCTION(AmdtNoteStd);
DBREF_DECLARE(AmdtNoteStd)

#endif // __NOTESTD_H

