/*--------------------------------------------------------------------------------------+
|
|     $Source: sdk/example/rebarSDK_PierVase.h $
|
|  $Copyright: (c) 2019 Bentley Systems, Incorporated. All rights reserved. $
|
+--------------------------------------------------------------------------------------*/
#pragma once

#include "RebarElements.h"

struct RebarSDKPierVaseData
{
    enum TieType
    {
        kBend,
        kCog,
        kHook
    };
    //PierVase
    BE_DATA_VALUE(double, Height)
    BE_DATA_VALUE(double, Depth)
    BE_DATA_VALUE(double, CapHeight)
    BE_DATA_VALUE(double, CapWidth)
    BE_DATA_VALUE(double, FootHeight)
    BE_DATA_VALUE(double, FootWidth)
    BE_DATA_VALUE(double, Cover)
    BE_DATA_VALUE(double, ShearSpacing)
    BE_DATA_REFER(BrString, ShearBarSize)
    BE_DATA_VALUE (double, LongitudinalSpacing)
    BE_DATA_REFER (BrString, LongitudinalBarSize)
    BE_DATA_VALUE(TieType, TieType)
public:
    RebarSDKPierVaseData()
        : m_Height(0.0)
        , m_Depth(0.0)
        , m_CapHeight(0.0)
        , m_CapWidth(0.0)
        , m_FootHeight(0.0)
        , m_FootWidth(0.0)
        , m_Cover(0.0)
        , m_ShearSpacing (0.0)
        , m_LongitudinalSpacing (0.0)
        , m_TieType(kBend)
    {
    }
};

class RebarSDKPierVase : public RebarAssembly, private RebarSDKPierVaseData
{
private:
	BE_DATA_REFER(BeMatrix, Placement)

	bool		m_bSetup;

    // rebar
    ElementId   m_stirrup_set_id;
    ElementId   m_front_set_id;
    ElementId   m_back_set_id;
    ElementId   m_left_set_id;
    ElementId   m_right_set_id;

    // optional
    virtual int GetPolymorphic() const override
    {
        return REX_Type::kLastRebarElement + kRebarAssembly + 1;
    }

    virtual WString GetDescriptionEx(ElementHandleCR eh) const override
    {
        return L"PierVase";
    }
    virtual WString GetPathDescriptionEx(ElementHandleCR eh) const override
    {
        return L"PierVase By SDK";
    }

    RebarSDKPierVase()
        : m_stirrup_set_id(0)
        , m_front_set_id(0)
        , m_back_set_id(0)
        , m_left_set_id(0)
        , m_right_set_id(0)
        , m_bSetup(false)
    {
    }

public:
	RebarSDKPierVase(ElementId id, DgnModelRefP modelRef)
        : RebarAssembly(id, modelRef)
        , m_stirrup_set_id(0)
        , m_front_set_id(0)
        , m_back_set_id(0)
        , m_left_set_id(0)
        , m_right_set_id(0)
        , m_bSetup(false)
    {
    }

    void GetData(RebarSDKPierVaseData &data) const
    {
        data = *this;
    }

	bool IsSetup()
	{
		return m_bSetup;
	}

	bool Setup(CPoint3D& origin, CPoint3D& X, const RebarSDKPierVaseData &data);

	bool CreatePierVaseSolid(EditElementHandleR tagEeh, DgnModelRefR modelRef);

    // hight is always negative
    bool GetRectFromHeight(double& width, double& length, double height, double cover);

    // for the handler
    ISolidPrimitivePtr CreatePierVaseGraphics(EditElementHandleR tagEeh, DgnModelRefR modelRef);

    virtual BentleyStatus GetPresentation(EditElementHandleR eeh, ViewContextR viewContext) override;

    virtual bool OnDoubleClick() override;

    int MakeVerticalXDirBar (RebarCurve &rebar, double xPos, double height, double diameter, double bendRadius, double bendLen, RebarEndTypes const& endTypes, bool isFront) const;
    RebarSetTag *MakeVerticalXDirBars (ElementId& setId, bool isFront, DgnModelRefP modelRef);
    int MakeVerticalYDirBar (RebarCurve &rebar, double yPos, double diameter, double bendRadius, double bendLen, RebarEndTypes const& endTypes, bool isRight) const;
    RebarSetTag *MakeVerticalYDirBars (ElementId& setId, bool isRight, DgnModelRefP modelRef);
    int MakeStirrup(RebarCurve &rebar, double z, double width, double depth, double cover, double diameter, double bendRadius, double bendLen, const RebarEndTypes &endTypes) const;
    RebarSetTag *MakeStirrups(DgnModelRefP modelRef);

    int MakeRebars (DgnModelRefP modelRef);

    bool GetHeightFromWidth(double& height, double width, double diameter) const;
    bool GetVerticalYDirPoints (bvector<BePoint3D>& points, double& vaseRadius, double yPos, double barDiameter, double bendRadius) const;

    BE_DECLARE_VMS(RebarSDKPierVase, RebarAssembly)
};

