void getHooks(std::vector<HookData> &hooks, TXsheet *xsh, int row, int col, TPointD dpiScale) { // nota. hook position is in the coordinate system of the parent object. // a inch is Stage::inch TXshCell cell = xsh->getCell(row, col); if (!cell.m_level) return; TStageObjectId columnId = TStageObjectId::ColumnId(col); // handle is the current handle (pivot) of the column. It can be H1,H2,... or A,B,C,... std::string handle = xsh->getStageObject(TStageObjectId::ColumnId(col))->getHandle(); bool handleIsHook = handle.find("H") == 0; TAffine aff = xsh->getPlacement(columnId, row); // imageDpiAff represent the scale factor between the image and the camera // derived by dpi match (i.e. ignoring geometric transformation) // cameraPos = imageDpiAff * imagePos TAffine imageDpiAff; if (cell.m_level->getSimpleLevel()) imageDpiAff = getDpiAffine(cell.m_level->getSimpleLevel(), cell.m_frameId, true); // center (inches) TPointD center = xsh->getCenter(columnId, row); // getHooks if (handleIsHook) center = TPointD(0, 0); // add the hook #0 (i.e. the regular center) hooks.push_back(HookData(xsh, col, 0, aff * TScale(Stage::inch) * center)); // add the regular hooks HookSet *hookSet = cell.m_level->getHookSet(); if (hookSet && hookSet->getHookCount() > 0) { for (int j = 0; j < hookSet->getHookCount(); j++) { Hook *hook = hookSet->getHook(j); if (hook && !hook->isEmpty()) { TPointD pos = hook->getAPos(cell.m_frameId); pos = aff * imageDpiAff * pos; hooks.push_back(HookData(xsh, col, j + 1, pos)); } } } }
TPointD XshHandleManager::getHandlePos(const TStageObjectId &id, const std::string &handle, int row) const { static const double unit = 8.0; assert(m_xsh->getScene()); if (handle == "") return TPointD(); else if (handle[0] == 'H' && handle.length() > 1) { // Hook port case if (!id.isColumn()) return TPointD(); int hookIndex = 0; { int h, hLength = handle.length(); for (h = 1; h != hLength; ++h) hookIndex = hookIndex * 10 + (handle[h] - '0'); } TStageObject *obj = m_xsh->getStageObject(id); if (const PlasticSkeletonDeformationP &def = obj->getPlasticSkeletonDeformation()) { int skelId = def->skeletonId(row); PlasticSkeleton skel; def->storeDeformedSkeleton(skelId, row, skel); int v = def->vertexIndex(hookIndex, skelId); return (v >= 0) ? TScale(1.0 / Stage::inch) * skel.vertex(v).P() : TPointD(); } --hookIndex; int col = id.getIndex(); TXshCell cell(m_xsh->getCell(row, col)); TXshLevel *xl = cell.m_level.getPointer(); if (!xl) return TPointD(); TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl) return TPointD(); Hook *hook = sl->getHookSet()->getHook(hookIndex); if (!hook) return TPointD(); TFrameId fid(cell.m_frameId); TPointD pos = hook->getAPos(fid) * (1.0 / Stage::inch); TPointD delta; for (int r = row - 1; r >= 0; --r) { cell = m_xsh->getCell(r, col); if (cell.m_level.getPointer() != xl) break; const TFrameId &precFid = cell.m_frameId; delta += computePassHook(fid, precFid, sl, hook); fid = precFid; } pos += delta * (1.0 / Stage::inch); pos = getDpiAffine(sl, cell.m_frameId, true) * pos; return pos; } else if ('A' <= handle[0] && handle[0] <= 'Z') return TPointD(unit * (handle[0] - 'B'), 0); else if ('a' <= handle[0] && handle[0] <= 'z') return TPointD(0.5 * unit * (handle[0] - 'b'), 0); else return TPointD(); }