//////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2025 Autodesk, Inc.  All rights reserved.
//
//  Use of this software is subject to the terms of the Autodesk license 
//  agreement provided at the time of installation or download, or which 
//  otherwise accompanies this software in either electronic or hard copy form.   
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __NOTESTD_H
#define __NOTESTD_H
#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;

///<summary>The Note Standard class. This class is derived from the AcmSymbolStd class.</summary>
class ACMSYMBB_CRX_DLLSHARE AmdtNoteStd : public AcmSymbolStd
{
  friend class AcmSymbbInternals;
  friend class AmdtNoteStdImp;
public:
  ACRX_DECLARE_MEMBERS(AmdtNoteStd);
  virtual ~AmdtNoteStd();

  ///<summary>This is record AmdtNoteStd::attachPoint.</summary>
  enum attachPoint {
    kNoPoint = 0,
    kTopText, // with overline
    kTopTopLine,
    kMiddleTopLine,
    kBottomTopLine,
    kMiddleText,
    kTopBottomLine,
    kMiddleBottomLine,
    kBottomBottomLine,
    kBottomText, // with underline    
    kTopLineRefLine,
    kUnderlineAllText,
  };
  ///<summary>This is record AmdtNoteStd::textAlignment.</summary>
  enum textAlignment {
    kLeft = 0,
    kCenter,
    kRight,
  };

  const ACHAR* getBaseSymStdClassName() const override;
  virtual AmdtNoteStd::attachPoint defaultAttachPoint() const = 0;


  bool getTemplate(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, 
                   LPCTSTR& value) const;


  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);

  ///<summary>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.</summary>
  bool changeValue(const AcArray<Adesk::Int32>& groupType, LPCTSTR tempName, LPCTSTR newValue, bool updateDimStyles = true);

  ///<summary>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.</summary>
  void setCompatibilityCondition(const AcArray<Adesk::Int32>& type);

  int numGroups(const bool onlyCompatible = false) const;

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

  ///<summary>returns all templates for the group with given type</summary>
  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);

  ///<summary>This is the method to distinguish the type of features a symbol is attached to:</summary>
  AcArray<Adesk::Int32> featTypes(const AcmSymbol* pSym) const;
  ///<summary>Sets the factory default values.</summary>
  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;
  ///<summary>As the standard updateMTextLoc function but optionally supports multi-path symbols through the optional iIndex parameter.</summary>
  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);

  void setDefaultLandingAndAttachPoint();
  ///<summary>Allows the SymStandard to define whether or not to enable multiple branches for the Note symbol. 
  ///The default implementation for this function returns false, thus disabling the multiple branch controls by default.</summary>
  virtual bool isMultiBranchEnabled() const;  

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

  bool addGroup(const AcArray<Adesk::Int32> type, CString& name);

private:
  AmdtNoteStdImp* mpImp;
  
  mutable AcDbMText mMText;
  mutable AcDbMText mMTextMax;
  mutable AcDbMText mMTextPrev;
};
DBREF_DECLARE(AmdtNoteStd)

#endif // __NOTESTD_H

