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);
   }
 }
示例#2
0
bool TMacroFx::analyze(const vector<TFxP> &fxs,
					   TFxP &root,
					   vector<TFxP> &roots,
					   vector<TFxP> &leafs)
{
	if (fxs.size() == 1)
		return false;
	else {
		leafs.clear();
		roots.clear();
		std::vector<TFxP>::const_iterator it = fxs.begin();
		for (; it != fxs.end(); ++it) {
			TFxP fx = *it;
			int inputInternalConnection = 0;
			int inputExternalConnection = 0;
			int outputInternalConnection = 0;
			int outputExternalConnection = 0;

			int i;

			// calcola se ci sono connessioni in input dall'esterno
			// verso l'interno e/o internamente a orderedFxs
			int inputPortCount = fx->getInputPortCount();
			for (i = 0; i < inputPortCount; ++i) {
				TFxPort *inputPort = fx->getInputPort(i);
				TFx *inputPortFx = inputPort->getFx();
				if (inputPortFx) {
					if (std::find_if(fxs.begin(), fxs.end(), MatchesFx(inputPortFx)) != fxs.end())
						++inputInternalConnection;
					else
						++inputExternalConnection;
				}
			}

			// calcola se ci sono connessioni in output dall'interno
			// verso l'esterno e/o internamente a orderedFxs
			int outputPortCount = fx->getOutputConnectionCount();
			for (i = 0; i < outputPortCount; ++i) {
				TFxPort *outputPort = fx->getOutputConnection(i);
				TFx *outputFx = outputPort->getOwnerFx();
				if (outputFx) {
					if (std::find_if(fxs.begin(), fxs.end(), MatchesFx(outputFx)) != fxs.end())
						++outputInternalConnection;
					else
						++outputExternalConnection;
				}
			}

			// se fx e' una radice
			if ((outputExternalConnection > 0) ||
				(outputExternalConnection == 0 && outputInternalConnection == 0)) {
				root = fx;
				roots.push_back(fx);
			}

			// se fx e' una foglia
			if (inputExternalConnection > 0 || fx->getInputPortCount() == 0 ||
				(inputExternalConnection == 0 && inputInternalConnection < fx->getInputPortCount())) {
				leafs.push_back(fx);
			}
		}

		if (roots.size() != 1)
			return false;
		else {
			if (leafs.size() == 0)
				return false;
		}

		return true;
	}
}