void TXshZeraryFxColumn::loadData(TIStream &is)
{
	TPersist *p = 0;
	is >> p;
	if (!p)
		return;

	TZeraryColumnFx *fx = dynamic_cast<TZeraryColumnFx *>(p);
	fx->addRef();
	if (m_zeraryColumnFx) {
		m_zeraryColumnFx->setColumn(0);
		m_zeraryColumnFx->release();
	}
	m_zeraryColumnFx = fx;
	m_zeraryColumnFx->setColumn(this);

	int r0, r1;
	bool touched = false;
	const TXshCell cell(m_zeraryFxLevel, TFrameId(1));
	string tagName;
	while (is.matchTag(tagName)) {
		if (tagName == "status") {
			int status;
			is >> status;
			setStatusWord(status);
		} else if (tagName == "cells") {
Ejemplo n.º 2
0
void SwatchCacheManager::setFx(const TFxP &fx)
{
	QMutexLocker locker(&m_mutex);

	//Update the fxs id data
	if (fx == TFxP()) {
		//Clear if no fx is set
		m_setFxId = 0;
		m_childrenFxIds.clear();
	} else {
		m_setFxId = fx->getIdentifier();
		m_childrenFxIds.clear();
		assert(m_setFxId != 0);

		TRasterFx *rfx = dynamic_cast<TRasterFx *>(fx.getPointer());
		assert(rfx);

		for (int i = 0; i < fx->getInputPortCount(); ++i) {
			//Fxs not allowing cache on the input port are skipped
			if (!rfx->allowUserCacheOnPort(i))
				continue;

			TFxPort *iport = fx->getInputPort(i);
			if (iport && iport->isConnected()) {
				TFx *child = iport->getFx();

				//In the zerary case, extract the actual fx
				TZeraryColumnFx *zcfx = dynamic_cast<TZeraryColumnFx *>(child);
				if (zcfx)
					child = zcfx->getZeraryFx();

				assert(child && child->getIdentifier() != 0);
				m_childrenFxIds.insert(child->getIdentifier());
			}
		}
	}

	//NOTE: Check if this should be avoided in some case...

	//Release the locks and clear the resources
	if (m_currEditedFxResult)
		m_currEditedFxResult->releaseLock();
	m_currEditedFxResult = TCacheResourceP();

	std::set<TCacheResourceP>::iterator it;
	for (it = m_swatchCacheContainer.begin(); it != m_swatchCacheContainer.end(); ++it)
		(*it)->releaseLock();
	m_swatchCacheContainer.clear();

#ifdef USE_SQLITE_HDPOOL
	TCacheResourcePool::instance()->releaseReferences("S");
#else
	for (it = m_genericCacheContainer.begin(); it != m_genericCacheContainer.end(); ++it)
		(*it)->releaseLock();
	m_genericCacheContainer.clear();
#endif
}
Ejemplo n.º 3
0
bool FxSelection::isSelected(TFxP fx) const {
  int i;
  for (i = 0; i < m_selectedFxs.size(); i++) {
    TFx *selectedFx      = m_selectedFxs[i].getPointer();
    TZeraryColumnFx *zfx = dynamic_cast<TZeraryColumnFx *>(selectedFx);
    if (zfx &&
        (fx.getPointer() == zfx || fx.getPointer() == zfx->getZeraryFx()))
      return true;
    if (fx.getPointer() == selectedFx) return true;
  }
  return false;
}
Ejemplo n.º 4
0
void FxGadgetController::onFxSwitched() {
  clearGadgets();
  bool enabled = false;
  TFx *fx      = m_fxHandle ? m_fxHandle->getFx() : 0;
  if (fx) {
    int referenceColumnIndex = fx->getReferenceColumnIndex();
    if (referenceColumnIndex == -1) {
      TObjectHandle *oh = m_tool->getApplication()->getCurrentObject();
      if (!oh->getObjectId().isCamera()) {
        oh->setObjectId(TStageObjectId::CameraId(0));
      }
      enabled = true;
    } else if (referenceColumnIndex == m_tool->getColumnIndex())
      enabled = true;
  }
  if (fx && enabled) {
    m_editingNonZeraryFx = true;
    TZeraryColumnFx *zfx = 0;
    if ((zfx = dynamic_cast<TZeraryColumnFx *>(fx)) ||
        dynamic_cast<TLevelColumnFx *>(fx))
    // WARNING! quick patch for huge bug:  I added the || with TLevelColumnFx;
    // before, the levels were considered as nonZeraryFx and the edit tool
    // gadget was not displayed! Vinz
    {
      if (zfx) fx          = zfx->getZeraryFx();
      m_editingNonZeraryFx = false;
    }

    // Parse the UI Concepts returned by the fx
    TParamUIConcept *uiConcepts = 0;
    int i, count;

    fx->getParamUIs(uiConcepts, count);

    for (i = 0; i < count; ++i) {
      FxGadget *gadget = allocateGadget(uiConcepts[i]);
      if (gadget) addGadget(gadget);
    }

    delete[] uiConcepts;
  } else
    m_editingNonZeraryFx = false;

  m_tool->invalidate();
}
Ejemplo n.º 5
0
bool FxSelection::isConnected() {
  if (m_selectedFxs.isEmpty()) return false;
  QList<TFx *> visitedFxs;
  visitFx(m_selectedFxs.at(0).getPointer(), visitedFxs);
  bool connected = true;
  QList<TFxP>::const_iterator it;
  TXsheet *xsh        = m_xshHandle->getXsheet();
  TFxSet *internalFxs = xsh->getFxDag()->getInternalFxs();
  for (it = m_selectedFxs.begin(); it != m_selectedFxs.end(); it++) {
    TFx *selectedFx = it->getPointer();
    TColumnFx *cfx  = dynamic_cast<TColumnFx *>(selectedFx);
    if (!cfx && !internalFxs->containsFx(selectedFx)) return false;
    TZeraryColumnFx *zfx = dynamic_cast<TZeraryColumnFx *>(selectedFx);
    if (zfx) selectedFx  = zfx->getZeraryFx();
    connected            = connected && visitedFxs.contains(selectedFx);
  }
  return connected;
}
Ejemplo n.º 6
0
void FxsData::setFxs(const QList<TFxP> &selectedFxs,
                     const QList<Link> &selectedLinks,
                     const QList<int> &columnIndexes, TXsheet *xsh) {
  // fx->clonedFx
  QMap<TFx *, TFx *> clonedFxs;
  for (int i = 0; i < selectedFxs.size(); i++) {
    TFx *fx = selectedFxs[i].getPointer();
    if (!canCopyFx(fx)) continue;
    TZeraryColumnFx *zerayFx = dynamic_cast<TZeraryColumnFx *>(fx);
    if (zerayFx) fx          = zerayFx->getZeraryFx();
    TFx *clonedFx            = fx->clone(false);
    TPointD pos;
    if (zerayFx)
      pos = zerayFx->getAttributes()->getDagNodePos();
    else
      pos = fx->getAttributes()->getDagNodePos();
    clonedFx->getAttributes()->setDagNodePos(pos);
    m_fxs.append(clonedFx);
    if (zerayFx)
      m_zeraryFxColumnSize[clonedFx] = zerayFx->getColumn()->getRowCount();
    m_visitedFxs[clonedFx]           = false;
    clonedFxs[fx]                    = clonedFx;

    TFx *linkedFx = fx->getLinkedFx();
    if (linkedFx && clonedFxs.contains(linkedFx))
      clonedFx->linkParams(clonedFxs[linkedFx]);
  }

  QList<int>::const_iterator it;
  for (it = columnIndexes.begin(); it != columnIndexes.end(); it++) {
    TXshColumn *col    = xsh->getColumn(*it);
    TXshColumn *newCol = col->clone();
    newCol->getFx()->getAttributes()->setDagNodePos(
        col->getFx()->getAttributes()->getDagNodePos());
    m_columns.append(newCol);
    clonedFxs[col->getFx()] = newCol->getFx();
  }

  linkFxs(clonedFxs, selectedLinks);
  checkConnectivity();
}
 DeleteFxsUndo(const QList<TFx *> &fxs) {
   TApp *app    = TApp::instance();
   FxDag *fxDag = app->getCurrentXsheet()->getXsheet()->getFxDag();
   for (int i = 0; i < (int)fxs.size(); i++) {
     TFx *fx              = fxs[i];
     TZeraryColumnFx *zfx = dynamic_cast<TZeraryColumnFx *>(fx);
     if (zfx) fx          = zfx->getZeraryFx();
     Node node;
     node.m_fx              = fx;
     node.m_xsheetConnected = fxDag->getTerminalFxs()->containsFx(fx);
     int j;
     for (j = 0; j < fx->getInputPortCount(); j++) {
       TFxP inputFx(fx->getInputPort(j)->getFx());
       int i;
       if (inputFx &&
           !fxDag->getTerminalFxs()->containsFx(inputFx.getPointer())) {
         for (i = 0; i < (int)m_inputConnectedToXsheet.size(); i++)
           if (m_inputConnectedToXsheet[i].getPointer() ==
               inputFx.getPointer())
             break;
         if (i == (int)m_inputConnectedToXsheet.size())
           m_inputConnectedToXsheet.push_back(inputFx);
       }
       node.m_inputLinks.push_back(inputFx);
     }
     for (j = 0; j < fx->getOutputConnectionCount(); j++) {
       TFxPort *port = fx->getOutputConnection(j);
       TFx *outFx    = port->getOwnerFx();
       if (outFx) {
         int k;
         for (k = 0; k < outFx->getInputPortCount(); k++)
           if (outFx->getInputPort(k)->getFx() == fx) break;
         if (k < outFx->getInputPortCount())
           node.m_outputLinks.push_back(std::make_pair(k, TFxP(outFx)));
       }
     }
     m_fxs.push_back(node);
   }
 }
Ejemplo n.º 8
0
void FxSelection::visitFx(TFx *fx, QList<TFx *> &visitedFxs) {
  if (visitedFxs.contains(fx)) return;
  TZeraryColumnFx *zfx = dynamic_cast<TZeraryColumnFx *>(fx);
  if (zfx) fx          = zfx->getZeraryFx();
  if (!canGroup(fx)) return;
  visitedFxs.append(fx);
  int i;
  for (i = 0; i < fx->getInputPortCount(); i++) {
    TFx *inputFx              = fx->getInputPort(i)->getFx();
    TZeraryColumnFx *onputZFx = dynamic_cast<TZeraryColumnFx *>(inputFx);
    if (onputZFx) inputFx     = onputZFx->getZeraryFx();
    if (!inputFx) continue;
    bool canBeGrouped = !inputFx->getAttributes()->isGrouped() ||
                        (inputFx->getAttributes()->getEditingGroupId() ==
                         fx->getAttributes()->getEditingGroupId());
    if (!visitedFxs.contains(inputFx) && isSelected(inputFx) && canBeGrouped)
      visitFx(inputFx, visitedFxs);
  }
  if (zfx) fx = zfx;
  if (fx->isZerary() && !zfx) {
    TXsheet *xsh    = m_xshHandle->getXsheet();
    int columnCount = xsh->getColumnCount();
    int j;
    for (j = 0; j < columnCount; j++) {
      TZeraryColumnFx *zerary =
          dynamic_cast<TZeraryColumnFx *>(xsh->getColumn(j)->getFx());
      if (zerary && zerary->getZeraryFx() == fx) {
        fx = zerary;
        break;
      }
    }
  }
  for (i = 0; i < fx->getOutputConnectionCount(); i++) {
    TFx *outputFx = fx->getOutputConnection(i)->getOwnerFx();
    if (!outputFx) continue;
    bool canBeGrouped = !outputFx->getAttributes()->isGrouped() ||
                        (outputFx->getAttributes()->getEditingGroupId() ==
                         fx->getAttributes()->getEditingGroupId());
    if (!visitedFxs.contains(outputFx) && isSelected(outputFx) && canBeGrouped)
      visitFx(outputFx, visitedFxs);
  }
}
Ejemplo n.º 9
0
std::vector<TStageObjectId> StageObjectsData::restoreObjects(std::set<int> &columnIndices, std::list<int> &restoredSpline,
															 TXsheet *xsh, int fxFlags, const TPointD &pos) const
{
	bool doClone = (fxFlags & eDoClone);
	bool resetFxDagPositions = (fxFlags & eResetFxDagPositions);

	QMap<TStageObjectId, TStageObjectId> idTable; // Trace stored/restored id pairings
	std::map<TFx *, TFx *> fxTable;					  // Same for fxs here
	std::vector<TStageObjectId> restoredIds;

	std::set<int>::iterator idxt = columnIndices.begin();
	int index = -1; // The actual column insertion index

	int i, elementsCount = m_elements.size();
	for (i = 0; i < elementsCount; ++i) {
		TStageObjectDataElement *element = m_elements[i];

		TCameraDataElement *cameraElement = dynamic_cast<TCameraDataElement *>(element);
		TColumnDataElement *columnElement = dynamic_cast<TColumnDataElement *>(element);

		// Restore the object depending on its specific type
		TStageObjectId restoredId = TStageObjectId::NoneId;

		if (!cameraElement && !columnElement)
			restoredId = element->restoreObject(xsh, pos != TConst::nowhere);
		else if (cameraElement)
			restoredId = cameraElement->restoreCamera(xsh, pos != TConst::nowhere);
		else if (columnElement) {
			// Build the column insertion index
			if (idxt != columnIndices.end())
				index = *idxt++;
			else {
				++index;
				columnIndices.insert(index);
			}

			// Restore the column element
			restoredId = columnElement->restoreColumn(xsh, index, fxFlags, pos != TConst::nowhere);

			FxDag *fxDag = xsh->getFxDag();

			TXshColumn *column = columnElement->m_column.getPointer();
			TXshColumn *pastedColumn = xsh->getColumn(index);

			TFx *fx = column->getFx();
			TFx *pastedFx = pastedColumn->getFx();

			if (fx && pastedFx)
				fxTable[fx] = pastedFx;

			// Enforce the correct terminality. Added columns are terminal by default.
			bool terminal = (fx && (m_terminalFxs.count(fx) > 0));
			if (!terminal)
				fxDag->getTerminalFxs()->removeFx(pastedFx);

			// In case we've cloned a zerary fx column, update the actual fx's data
			if (TXshZeraryFxColumn *zc = dynamic_cast<TXshZeraryFxColumn *>(pastedColumn)) {
				TZeraryColumnFx *zfx = zc->getZeraryColumnFx();
				TFx *zeraryFx = zfx->getZeraryFx();
				if (zeraryFx && doClone) {
					std::wstring app = zeraryFx->getName();
					fxDag->assignUniqueId(zeraryFx);
					zeraryFx->setName(app);
				}
			}
		}

		// Remember stored/restored stage object pairings
		idTable[element->m_params->m_id] = restoredId;
		restoredIds.push_back(restoredId);
	}

	// Apply stage object-parental relationships
	for (i = 0; i < elementsCount; ++i) {
		TStageObjectDataElement *element = m_elements[i];

		TStageObjectId id = element->m_params->m_id;
		TStageObjectId parentId = element->m_params->m_parentId;

		TStageObjectId pastedId = idTable[id];
		TStageObjectId pastedParentId = parentId;

		if (parentId.isColumn()) // Why discriminating for columns only ?
		{
			//Columns are redirected to table ids. If no redirected parent exists, store
			//a void value that will be avoided later
			QMap<TStageObjectId, TStageObjectId>::iterator it = idTable.find(parentId);
			pastedParentId = (it == idTable.end()) ? TStageObjectId::NoneId : it.value();
		}

		if (pastedParentId != TStageObjectId::NoneId) {
			xsh->setStageObjectParent(pastedId, pastedParentId);
			TStageObject *pastedObj = xsh->getStageObject(pastedId);

			// Shouldn't these be done outside ?
			pastedObj->setHandle(element->m_params->m_handle);
			pastedObj->setParentHandle(element->m_params->m_parentHandle);
		}
	}

	// Iterate stored fxs
	std::set<TFx *>::const_iterator fxt, end = m_fxs.end();
	for (fxt = m_fxs.begin(); fxt != end; ++fxt) {
		TFx *fxOrig = *fxt, *fx = fxOrig;

		// Only NOT COLUMN fxs - ie internal fxs
		if (fxTable.find(fxOrig) != fxTable.end())
			continue;

		// Internal fxs

		if (doClone) {
			fx = fxOrig->clone(false);

			fx->setName(fxOrig->getName());
			fx->getAttributes()->setId(fxOrig->getAttributes()->getId());
			fx->getAttributes()->passiveCacheDataIdx() = -1;

			if (resetFxDagPositions)
				fx->getAttributes()->setDagNodePos(TConst::nowhere);

			xsh->getFxDag()->assignUniqueId(fx);
		}

		fxTable[fxOrig] = fx;

		// Insert the passed fx in the xsheet
		TOutputFx *outFx = dynamic_cast<TOutputFx *>(fx);
		if (!outFx)
			xsh->getFxDag()->getInternalFxs()->addFx(fx);
		else
			xsh->getFxDag()->addOutputFx(outFx);

		if (m_terminalFxs.count(fxOrig) > 0)
			xsh->getFxDag()->getTerminalFxs()->addFx(fx);

		if (!doClone) {
			// Err.... don't remember. Inquire further? :|
			int fxTypeCount = xsh->getFxDag()->getFxTypeCount(fx);

			int maxFxTypeId = std::max(fxTypeCount, fx->getAttributes()->getId());
			xsh->getFxDag()->updateFxTypeTable(fx, maxFxTypeId);
			xsh->getFxDag()->updateFxIdTable(fx);
		}

		bool isLinked = (fxOrig->getLinkedFx() != fxOrig);
		if (isLinked) {
			if (m_fxs.find(fxOrig->getLinkedFx()) == m_fxs.end())
				fx->linkParams(fxOrig->getLinkedFx());
			else {
				TFx *linkedFx, *oldLinkedFx = fxOrig->getLinkedFx();
				if (doClone) {
					// Clone the linked fx too
					linkedFx = fx->clone(false);
					linkedFx->linkParams(fx);

					linkedFx->setName(oldLinkedFx->getName());
					linkedFx->getAttributes()->setId(oldLinkedFx->getAttributes()->getId());
					linkedFx->getAttributes()->passiveCacheDataIdx() = -1;

					if (resetFxDagPositions)
						linkedFx->getAttributes()->setDagNodePos(TConst::nowhere);
					else
						linkedFx->getAttributes()->setDagNodePos(oldLinkedFx->getAttributes()->getDagNodePos());

					xsh->getFxDag()->assignUniqueId(linkedFx);
				} else
					linkedFx = oldLinkedFx;

				fxTable[oldLinkedFx] = linkedFx;

				xsh->getFxDag()->getInternalFxs()->addFx(linkedFx);
				if (m_terminalFxs.count(oldLinkedFx) > 0)
					xsh->getFxDag()->getTerminalFxs()->addFx(linkedFx);

				if (!doClone) {
					int fxTypeCount = xsh->getFxDag()->getFxTypeCount(linkedFx);
					int maxFxTypeId = std::max(fxTypeCount, linkedFx->getAttributes()->getId());
					xsh->getFxDag()->updateFxTypeTable(linkedFx, maxFxTypeId);
					xsh->getFxDag()->updateFxIdTable(linkedFx);
				}
			}
		}
	}

	// Update the link, like in functions above
	if (!fxTable.empty() && doClone)
		updateFxLinks(fxTable);

	// Paste any associated spline (not stored im m_splines)
	std::map<TStageObjectSpline *, TStageObjectSpline *> splines;
	for (i = 0; i < (int)restoredIds.size(); ++i) {
		TStageObjectId id = restoredIds[i];
		TStageObject *obj = xsh->getStageObject(id);

		TStageObjectSpline *spline = obj->getSpline();
		if (!spline)
			continue;

		TStageObjectTree *objTree = xsh->getStageObjectTree();
		if (objTree->containsSpline(spline)) // No need to add it if it's already there
			continue;

		std::map<TStageObjectSpline *, TStageObjectSpline *>::iterator it = splines.find(spline);
		if (it != splines.end()) {
			// Seems that multiple objects can have the same spline...
			// BTW, shouldn't this case stop at the continue before ?
			obj->setSpline(it->second);
			continue;
		}

		// The spline was not found. Clone and add it to the xsheet
		TStageObjectSpline *newSpline = spline->clone(); // Not checking doClone ?
		objTree->assignUniqueSplineId(newSpline);
		objTree->insertSpline(newSpline);
		obj->setSpline(newSpline);

		splines[spline] = newSpline;
	}

	//paste stored path
	QList<TSplineDataElement *>::const_iterator splinIt;
	for (splinIt = m_splines.begin(); splinIt != m_splines.end(); ++splinIt) {
		TStageObjectTree *objTree = xsh->getStageObjectTree();
		TSplineDataElement *splineEl = *splinIt;
		TStageObjectSpline *spline = splineEl->restoreSpline(fxFlags);
		if (doClone)
			objTree->assignUniqueSplineId(spline);
		objTree->insertSpline(spline);
		restoredSpline.push_back(spline->getId());
	}

	xsh->updateFrameCount();

	if (pos != TConst::nowhere) {
		// Update objects positions depending on the externally supplied pos

		TPointD middlePos;
		int count = 0;

		for (i = 0; i < (int)restoredIds.size(); ++i) {
			TStageObjectId id = restoredIds[i];
			TStageObject *obj = xsh->getStageObject(id);

			TPointD oldPos = obj->getDagNodePos();
			if (oldPos == TConst::nowhere)
				continue;

			middlePos += oldPos;
			++count;
		}

		middlePos = TPointD(middlePos.x / count, middlePos.y / count);
		TPointD offset = pos - middlePos;

		for (i = 0; i < (int)restoredIds.size(); ++i) {
			TStageObjectId id = restoredIds[i];
			TStageObject *obj = xsh->getStageObject(id);

			TPointD oldPos = obj->getDagNodePos();
			if (oldPos == TConst::nowhere)
				continue;

			obj->setDagNodePos(oldPos + offset);
		}
	}

	return restoredIds;
}