/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "SmileyDbMultiModesGripPE.h" #include "SmileyDb.h" #include "DbCommandContext.h" #include "Gs/Gs.h" #include "RxVariantValue.h" //######################################################################################## //############### SmileyMultiModesGripPE ############## //######################################################################################## ODRX_NO_CONS_DEFINE_MEMBERS(OdGripSmileyMultiModeAppData, OdRxObject); bool AsdkSmileyMultiModesGripPE::getGripModes(const OdDbEntity* pEnt, OdDbGripData* pGripData, OdArray& modes, unsigned int& curMode) const { if (!pEnt || !pGripData) return false; OdGripSmileyMultiModeAppDataPtr appData = static_cast(pGripData->appData()); if (!appData) return false; appData->getGripModes(modes); curMode = appData->mode(); return true; } unsigned int AsdkSmileyMultiModesGripPE::mode(OdDbEntity*, OdDbGripData* pGripData) const { OdGripSmileyMultiModeAppDataPtr appData = static_cast(pGripData->appData()); return appData->mode(); } OdDbMultiModesGripPE::GripMode AsdkSmileyMultiModesGripPE::modeEx(OdDbEntity*, OdDbGripData* pGripData) const { OdGripSmileyMultiModeAppDataPtr appData = static_cast(pGripData->appData()); return appData->gripMode(); } namespace Trackers { class ScaleTracker : public OdStaticRxObject { public: ScaleTracker() = delete; ScaleTracker(const OdSmartPtr& org, const OdGePoint3d center) : m_pSmiley(org->clone()), m_center(center) { } virtual void setValue(const OdGePoint3d& value) { m_pSmiley->scaleRadius(m_center.distanceTo(value)); } virtual int addDrawables(OdGsView* pView) { OdRxDictionaryPtr pProps = pView->device()->properties(); if (!pProps.isNull() && pProps->has(OD_T("DrawDragging"))) pProps->putAt(OD_T("DrawDragging"), OdRxVariantValue(true)); pView->add(m_pSmiley, 0); return 1; } virtual void removeDrawables(OdGsView* pView) { OdRxDictionaryPtr pProps = pView->device()->properties(); if (!pProps.isNull() && pProps->has(OD_T("DrawDragging"))) pProps->putAt(OD_T("DrawDragging"), OdRxVariantValue(false)); pView->erase(m_pSmiley); } private: OdSmartPtr m_pSmiley; const OdGePoint3d m_center; }; class StretchTracker : public OdStaticRxObject { public: StretchTracker() = delete; StretchTracker(OdSmartPtr& org, const OdIntArray &indices, const OdGePoint3d &pnt) : m_pSmiley(org->clone()), m_indices(indices), m_prev(pnt) { } virtual void setValue(const OdGePoint3d& value) { m_pSmiley->subMoveGripPointsAt(m_indices, value - m_prev); m_prev = value; } virtual int addDrawables(OdGsView* pView) { OdRxDictionaryPtr pProps = pView->device()->properties(); if (!pProps.isNull() && pProps->has(OD_T("DrawDragging"))) pProps->putAt(OD_T("DrawDragging"), OdRxVariantValue(true)); pView->add(m_pSmiley, 0); return 1; } virtual void removeDrawables(OdGsView* pView) { OdRxDictionaryPtr pProps = pView->device()->properties(); if (!pProps.isNull() && pProps->has(OD_T("DrawDragging"))) pProps->putAt(OD_T("DrawDragging"), OdRxVariantValue(false)); pView->erase(m_pSmiley); } private: OdSmartPtr m_pSmiley; const OdIntArray m_indices; OdGePoint3d m_prev; }; } bool AsdkSmileyMultiModesGripPE::setMode(OdDbEntity* pEnt, OdDbGripData* pGripData, unsigned int newMode) { OdSmartPtr pSmiley = pEnt; OdDbDatabase* pDb = pSmiley->database(); OdDbCommandContextPtr pCmdCtx = OdDbCommandContext::registredCommandContext(pDb); OdDbUserIO* pIO = pCmdCtx->dbUserIO(); if (!pGripData) return false; OdGripSmileyMultiModeAppDataPtr appData = static_cast(pGripData->appData()); if (!appData) return false; appData->setMode(newMode); const OdDbMultiModesGripPE::GripMode curMode = appData->gripMode(); const OdGePoint3d gripPnt = pGripData->gripPoint(); try { switch (newMode) { case 101: { // Stretch OdIntArray indices; indices.append(appData->lineGripType()); Trackers::StretchTracker tracker(pSmiley, indices, gripPnt); OdGePoint3d pnt = pIO->getPoint(curMode.CLIPromptString, OdEd::kGptRubberBand, &gripPnt, curMode.CLIKeywordList, &tracker); pSmiley->subMoveGripPointsAt(indices, pnt - gripPnt); break; } case 102: { // Scale const OdGePoint3d center = pSmiley->center(); Trackers::ScaleTracker tracker(pSmiley, center); OdGePoint3d pnt = pIO->getPoint(curMode.CLIPromptString, OdEd::kGptRubberBand, &gripPnt, curMode.CLIKeywordList, &tracker); pSmiley->scaleRadius(center.distanceTo(pnt)); break; } case 103: { // Default smile const double r = pSmiley->radius(); pSmiley->setEyesApart(r * 0.9); pSmiley->setEyesHeight(r * 0.4); pSmiley->setEyeSize(r * 0.15); OdGeVector3d vecstart((r * 0.9) * sin(1.25 * kPi), (r * 0.9) * cos(1.25 * kPi), 0), vecend((r * 0.9) * cos(1.75 * kPi), (r * 0.9) * sin(1.75 * kPi), 0), vecbottom(0, -r, 0); OdGePoint3d mouthcen(pSmiley->center()); mouthcen.y += r * 0.4; pSmiley->setMouth(mouthcen + vecstart, mouthcen + vecbottom, mouthcen + vecend); break; } case 104: { // Low Eyes pSmiley->setEyeSize(pSmiley->radius() * 0.15); pSmiley->setEyesApart(pSmiley->radius() * 0.6); pSmiley->setEyesHeight(0); break; } case 105: { // High Eyes pSmiley->setEyeSize(pSmiley->radius() * 0.15); pSmiley->setEyesApart(pSmiley->radius() * 0.6); pSmiley->setEyesHeight(pSmiley->radius() * 0.7); break; } case 106: { // White skin pSmiley->setColorIndex(0); break; } case 107: { // Red skin pSmiley->setColorIndex(1); break; } default: return false; } } catch (const OdEdCancel&) { return false; } return true; } OdDbMultiModesGripPE::GripType AsdkSmileyMultiModesGripPE::gripType(OdDbEntity*, OdDbGripData* pGripData) const { if (pGripData) { OdGripSmileyMultiModeAppDataPtr appData = static_cast(pGripData->appData()); if (appData) return appData->gripType(); } return OdDbMultiModesGripPE::kPrimary; } void AsdkSmileyMultiModesGripPE::reset(OdDbEntity*) {} void OdGripSmileyMultiModeAppData::getGripModes(OdArray& modes) { for (const auto& mode : m_modes) modes.append(mode.second); } bool OdGripSmileyMultiModeAppData::getIndices(OdIntArray& indices) const { indices.append(m_smileyGripType); return true; } void OdGripSmileyMultiModeAppData::initGripModes() { if (!m_modes.empty()) return; { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 101; mode.DisplayString = "Stretch"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** STRETCH **"; mode.CLIPromptString = "Specify stretch point:"; m_modes[mode.Mode] = mode; } if (m_smileyGripType == OdGripSmileyMultiModeAppData::SMILE_BS || m_smileyGripType == OdGripSmileyMultiModeAppData::SMILE_LS || m_smileyGripType == OdGripSmileyMultiModeAppData::SMILE_RS || m_smileyGripType == OdGripSmileyMultiModeAppData::SMILE_TS ) { { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 102; mode.DisplayString = "Scale"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** SCALE **"; mode.CLIPromptString = "Specify scale:"; m_modes[mode.Mode] = mode; } } if (m_smileyGripType == OdGripSmileyMultiModeAppData::CENTER) { { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 103; mode.DisplayString = "Default smile"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** DEFAULT SMILE **"; m_modes[mode.Mode] = mode; } { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 104; mode.DisplayString = "Low Eyes"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** LOW EYES **"; m_modes[mode.Mode] = mode; } { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 105; mode.DisplayString = "High Eyes"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** HIGH EYES **"; m_modes[mode.Mode] = mode; } { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 106; mode.DisplayString = "White skin"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** WHITE SKIN **"; m_modes[mode.Mode] = mode; } { OdDbMultiModesGripPE::GripMode mode; mode.Mode = 107; mode.DisplayString = "Red skin"; mode.ActionType = OdDbMultiModesGripPE::GripActionType::kImmediate; mode.CLIDisplayString = "** RED SKIN **"; m_modes[mode.Mode] = mode; } } }