void InstMod::initBrig() {
  initBrigBase(sizeof(Brig::BrigInstMod), Brig::BRIG_KIND_INST_MOD);
  Inst::initBrig();
  modifier().initBrig();
  brig()->pack = Brig::BRIG_PACK_NONE;
  brig()->reserved = 0;
}
void DesignDocumentView::fromText(const QString &text)
{
    QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
    inputModel->setFileUrl(model()->fileUrl());
    QPlainTextEdit textEdit;
    QString imports;
    foreach (const Import &import, model()->imports())
        imports += QStringLiteral("import ") + import.toString(true) + QLatin1Char(';') + QLatin1Char('\n');

    textEdit.setPlainText(imports + text);
    NotIndentingTextEditModifier modifier(&textEdit);

    QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, nullptr));
    rewriterView->setCheckSemanticErrors(false);
    rewriterView->setTextModifier(&modifier);
    inputModel->setRewriterView(rewriterView.data());

    rewriterView->restoreAuxiliaryData();

    if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
        ModelMerger merger(this);
        try {
            merger.replaceModel(rewriterView->rootModelNode());
        } catch(Exception &/*e*/) {
            /* e.showException(); Do not show any error if the clipboard contains invalid QML */
        }
    }
}
Example #3
0
//Produção ModifierList'
ModifierListNode* modifierListLinha(ModifierNode* modV){
     printf("ModifierList'\n");                     
     if (lookaheadPertenceFirst(Modifier) == 1){ 
          ModifierListNode* modifierListLinhaVar = modifierListLinha(modifier());
          return new ModifierListNode(modV,modifierListLinhaVar);
     }else return new ModifierListNode(modV);     
}
QString DesignDocumentView::toText() const
{
    QScopedPointer<Model> outputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
    outputModel->setFileUrl(model()->fileUrl());
    QPlainTextEdit textEdit;

    QString imports;
    foreach (const Import &import, model()->imports()) {
        if (import.isFileImport())
            imports += QStringLiteral("import ") + QStringLiteral("\"") + import.file() + QStringLiteral("\"")+ QStringLiteral(";\n");
        else
            imports += QStringLiteral("import ") + import.url() + QStringLiteral(" ") + import.version() + QStringLiteral(";\n");
    }

    textEdit.setPlainText(imports +  QStringLiteral("Item {\n}\n"));
    NotIndentingTextEditModifier modifier(&textEdit);

    QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, nullptr));
    rewriterView->setCheckSemanticErrors(false);
    rewriterView->setTextModifier(&modifier);
    outputModel->setRewriterView(rewriterView.data());

    ModelMerger merger(rewriterView.data());

    merger.replaceModel(rootModelNode());

    ModelNode rewriterNode(rewriterView->rootModelNode());

    rewriterView->writeAuxiliaryData();
    return rewriterView->extractText({rewriterNode}).value(rewriterNode) + rewriterView->getRawAuxiliaryData();
    //get the text of the root item without imports
}
Example #5
0
//Produção ModifierList
ModifierListNode* modifierList(){
      printf("ModifierList\n");                   
      ModifierNode* modfierVar = modifier();
      ModifierListNode* modifierListLinhaVar = modifierListLinha(modfierVar);
     return modifierListLinhaVar;
   
}
void DirectiveFbarrier::initBrig() {
  initBrigBase(sizeof(Brig::BrigDirectiveFbarrier), Brig::BRIG_KIND_DIRECTIVE_FBARRIER);
  Directive::initBrig();
  brig()->name = 0;
  modifier().initBrig();
  brig()->linkage = Brig::BRIG_LINKAGE_NONE;
  brig()->reserved = 0;
}
Example #7
0
filter_result 
NumericFilter::Filter (BMessage *msg, BHandler **handler)
{
  filter_result result = B_DISPATCH_MESSAGE;
  switch (msg->what)
  {
    case B_KEY_DOWN:
    {
      uint32 modifier (msg->FindInt32 ("modifiers"));
      const char *bytes (msg->FindString ("bytes"));

      if ((modifier & B_SHIFT_KEY) == 0
        && (modifier & B_CONTROL_KEY) == 0
        && (modifier & B_OPTION_KEY) == 0
        && (modifier & B_COMMAND_KEY) == 0)
      {
        switch (bytes[0])
        {
          case B_BACKSPACE:
          case B_LEFT_ARROW:
          case B_RIGHT_ARROW:
          case B_HOME:
          case B_END:
          case B_TAB:
            break;

          case B_ENTER:
            // for some stupid reason BTextControl on R5 does not always Invoke() when
            // you hit enter, so forcing the issue here.
            if (dynamic_cast<BTextView *>(*handler))
            {
              dynamic_cast<BInvoker *>(((BView *)*handler)->Parent())->Invoke();
            }
            break;
            
          default:
            if (!isdigit(bytes[0]))
              result = B_SKIP_MESSAGE;
            break;
        }
      }
      else if ((modifier & B_SHIFT_KEY) != 0)
      {
        if (bytes[0] == B_LEFT_ARROW
        ||  bytes[0] == B_RIGHT_ARROW
        ||  bytes[0] == B_HOME
        ||  bytes[0] == B_END
        ||  bytes[0] == B_TAB)
          break;
        else
          result = B_SKIP_MESSAGE;
      }
    }
    break;
  }
  return result;
}
Example #8
0
ButtonmapModifier*
ButtonmapModifier::from_string(const std::string& args)
{
  std::auto_ptr<ButtonmapModifier> modifier(new ButtonmapModifier);

  process_name_value_string(args, boost::bind(&ButtonmapModifier::add, modifier.get(), 
                                              boost::bind(&ButtonMapping::from_string, _1, _2)));

  return modifier.release();
}
void InstMem::initBrig() {
  initBrigBase(sizeof(Brig::BrigInstMem), Brig::BRIG_KIND_INST_MEM);
  Inst::initBrig();
  brig()->segment = Brig::BRIG_SEGMENT_NONE;
  brig()->align = Brig::BRIG_ALIGNMENT_NONE;
  modifier().initBrig();
  for (int i=0;i<3;i++) {
    brig()->reserved[i] = 0;
  }
}
Example #10
0
bool Version::candidateGreaterThanCurrent(const VersionThing & candidateVersionThing)
{
	VersionThing myVersionThing;
	myVersionThing.majorVersion = majorVersion().toInt();
	myVersionThing.minorVersion = minorVersion().toInt();
	myVersionThing.minorSubVersion = minorSubVersion().toInt();
	myVersionThing.releaseModifier = modifier();

	return greaterThan(myVersionThing, candidateVersionThing); 
}
Example #11
0
ListeChars AExtension::resultat()
{
	ListeChars tmp = donnees;
	tmp = modifier(tmp);
	if (modification_suivante)
	{
		(*modification_suivante) << tmp;
		tmp = modification_suivante->resultat();
	}
	effacerDonnees();
	return tmp;
}
Example #12
0
ButtonmapModifier*
ButtonmapModifier::from_option(const std::vector<ButtonMappingOption>& mappings)
{
  std::auto_ptr<ButtonmapModifier> modifier(new ButtonmapModifier);
  
  for(std::vector<ButtonMappingOption>::const_iterator i = mappings.begin(); i != mappings.end(); ++i)
  {
    modifier->add(ButtonMapping::from_string(i->lhs, i->rhs));
  }

  return modifier.release();
}
void DirectiveExecutable::initBrig() {
  Directive::initBrig();
  brig()->name = 0;
  brig()->outArgCount = 0;
  brig()->inArgCount = 0;
  brig()->firstInArg = 0;
  brig()->firstCodeBlockEntry = 0;
  brig()->nextModuleEntry = 0;
  brig()->codeBlockEntryCount = 0;
  modifier().initBrig();
  brig()->linkage = Brig::BRIG_LINKAGE_NONE;
  brig()->reserved = 0;
}
void DirectiveVariable::initBrig() {
  initBrigBase(sizeof(Brig::BrigDirectiveVariable), Brig::BRIG_KIND_DIRECTIVE_VARIABLE);
  Directive::initBrig();
  brig()->name = 0;
  brig()->init = 0;
  brig()->segment = Brig::BRIG_SEGMENT_NONE;
  brig()->align = Brig::BRIG_ALIGNMENT_NONE;
  dim().initBrig();
  modifier().initBrig();
  brig()->linkage = Brig::BRIG_LINKAGE_NONE;
  brig()->allocation = Brig::BRIG_ALLOCATION_NONE;
  brig()->reserved = 0;
}
Example #15
0
void test_HalfedgeDS_decorator3() {
    // Simple instantiation of the default halfedge data structure.
    typedef CGAL::HalfedgeDS_default<Dummy_traits_2>  HDS;
    typedef CGAL::HalfedgeDS_decorator<HDS>          Decorator;

    CGAL_USE_TYPE(HDS::Halfedge_handle);
    CGAL_USE_TYPE(HDS::Face_handle);

    HDS hds;

    Build_triangle<HDS> modifier(0,0);
    modifier(hds);
    modifier.x_=33;
    modifier.y_=33;
    modifier(hds);


    Decorator decorator(hds);
    decorator.keep_largest_connected_components(1);

    hds.normalize_border();

    assert( hds.size_of_vertices() == 4);
    assert( hds.size_of_halfedges() == 10);
    assert( hds.size_of_faces() == 2);
    assert( decorator.is_valid( false, 4));

    decorator.vertices_erase(hds.vertices_begin());
    decorator.vertices_erase(hds.vertices_begin(), hds.vertices_end());

    decorator.faces_erase(hds.faces_begin());
    decorator.faces_erase(hds.faces_begin(), hds.faces_end());

    assert( hds.size_of_vertices() == 0);
    assert( hds.size_of_halfedges() == 10);
    assert( hds.size_of_faces() == 0);

}
Example #16
0
void ts::server::Stage_assembler::Impl::on_state_change(cup::Cup_state old_state, cup::Cup_state new_state)
{
    if (new_state == cup::Cup_state::Awaiting_initialization)
    {
        initialize_stage_data();

        // Apply the stage data modifiers
        for (const auto& modifier : modifiers_)
        {
            modifier(*self_);
        }        

        cup_controller_->initialize_action(stage_data_);
    }
}
Example #17
0
void FGAEffectModifierContainer::AddModifier(const FGAEffectModifierSpec& ModSpec, const FGameplayTagContainer& Tags,
	const FGAEffectHandle HandleIn,
	TSharedPtr<FGAActiveDuration> EffectPtr)
{
	FString complexString = Tags.ToString();
	FString simpleString = Tags.ToStringSimple();
	FName test(*simpleString);

	for (const FGameplayTag& tag : Tags)
	{
		FGAEffectModifier& mods = Modifiers.FindOrAdd(tag);

		FGAModifier modifier(ModSpec.Mod, ModSpec.DirectModifier.Value, EffectPtr);
		modifier.ModifierType = ModSpec.ModifierType;
		mods.AddBonus(modifier, HandleIn);
	}
}
PyObject *py_ue_skeleton_add_bone(ue_PyUObject *self, PyObject * args)
{

	ue_py_check(self);

	char *name;
	int parent_index;
	PyObject *py_transform;
	if (!PyArg_ParseTuple(args, "siO:skeleton_add_bone", &name, &parent_index, &py_transform))
		return nullptr;

	USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
	if (!skeleton)
		return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");

	ue_PyFTransform *transform = py_ue_is_ftransform(py_transform);
	if (!transform)
		return PyErr_Format(PyExc_Exception, "argument is not a FTransform");

	if (skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))) > -1)
	{
		return PyErr_Format(PyExc_Exception, "bone %s already exists", name);
	}

#if WITH_EDITOR
	skeleton->PreEditChange(nullptr);
#endif

	{
		const FReferenceSkeleton &ref = skeleton->GetReferenceSkeleton();
		// horrible hack to modify the skeleton in place
		FReferenceSkeletonModifier modifier((FReferenceSkeleton &)ref, skeleton);

		TCHAR *bone_name = UTF8_TO_TCHAR(name);

		modifier.Add(FMeshBoneInfo(FName(bone_name), FString(bone_name), parent_index), transform->transform);
	}


#if WITH_EDITOR
	skeleton->PostEditChange();
#endif
	skeleton->MarkPackageDirty();

	return PyLong_FromLong(skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))));
}
Example #19
0
// test driver
static
void test_for_error(void (*modifier)(std::string&), void (*validator)(const fix_message*))
{
	std::string msg(m, sizeof(m) - 1);

	if(modifier)
		modifier(msg);

	msg = make_fix_message(msg.c_str());

	fix_parser* const parser = create_fix_parser(m_message_classifier);
	const fix_message* const pm = get_first_fix_message(parser, msg.c_str(), msg.size());

	ensure(pm);
	validator(pm);
	ensure(!get_next_fix_message(parser));
	free_fix_parser(parser);
}
Example #20
0
bool _gmp_modify(GumpDB db, int id, bool (*modifier)(void * r)) {
  void * record = malloc(db->size_of_data);

  if (record == NULL) { return false; }

  bool result = _gmp_retrieve(db, id, record);

  if (!result) { free(record); return false; }

  result = modifier(record);

  if (!result) { free(record); return false; }

  result = _gmp_set(db, id, record);

  if (!result) { free(record); }

  return result;
}
 wxString KeyboardShortcut::asJsonString() const {
     wxString str;
     str << "{ key:" << key() << ", modifiers: [";
     
     bool hadModifier = false;
     for (size_t i = 0; i < 3; ++i) {
         if (hasModifier(i)) {
             if (hadModifier)
                 str << ", ";
             str << modifier(i);
             hadModifier = true;
         } else {
             hadModifier = false;
         }
     }
     
     str << "] }";
     
     return str;
 }
void DesignDocumentControllerView::fromText(QString text)
{
    QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
    inputModel->setFileUrl(model()->fileUrl());
    QPlainTextEdit textEdit;
    QString imports;
    foreach (const Import &import, model()->imports())
        imports += import.toString(true, true) + "\n";

    textEdit.setPlainText(imports + text);
    NotIndentingTextEditModifier modifier(&textEdit);

    QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
    rewriterView->setCheckSemanticErrors(false);
    rewriterView->setTextModifier(&modifier);
    inputModel->attachView(rewriterView.data());

    if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
        ModelMerger merger(this);
        merger.replaceModel(rewriterView->rootModelNode());
    }
}
Example #23
0
static OBJECT
getmod(void)				/* get current modifier ID */
{
	char	*mnam;
	OBJECT	mod;

	if (!havemats)
		return(OVOID);
	if (!strcmp(material, VOIDID))
		return(OVOID);
	if (material[0])		/* prefer usemtl statements */
		mnam = material;
	else if (group[0])		/* else use group name */
		mnam = group;
	else
		return(OVOID);
	mod = modifier(mnam);
	if (mod == OVOID) {
		sprintf(errmsg, "%s: undefined modifier \"%s\"",
				inpfile, mnam);
		error(USER, errmsg);
	}
	return(mod);
}
Example #24
0
int main(int argc, char* argv[])
{
    // ensure proper usage
    if (argc != 4)
    {
        printf("Usage: ./resize f infile outfile\n");
        return 1;
    }

    // remember filenames and factor amt
    float factor = atof(argv[1]);
    char* infile = argv[2];
    char* outfile = argv[3];
    
    // open input file 
    FILE* inptr = fopen(infile, "r");
    if (inptr == NULL)
    {
        printf("Could not open %s.\n", infile);
        return 2;
    }

    // open output file
    FILE* outptr = fopen(outfile, "w+"); // r+ is used for reading and writing
    if (outptr == NULL)
    {
        fclose(inptr);
        fprintf(stderr, "Could not create %s.\n", outfile);
        return 3;
    }

    // read infile's BITMAPFILEHEADER
    BITMAPFILEHEADER bf;
    fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

    // read infile's BITMAPINFOHEADER
    BITMAPINFOHEADER bi;
    fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);

    // ensure infile is (likely) a 24-bit uncompressed BMP 4.0
    if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || 
        bi.biBitCount != 24 || bi.biCompression != 0)
    {
        fclose(outptr);
        fclose(inptr);
        fprintf(stderr, "Unsupported file format.\n");
        return 4;
    }

    // MODIFY OUTFILE HEADERS
        
    // save original width and height for later use
    int orgHeight = bi.biHeight;
    int orgWidth = bi.biWidth;
    
    // modify outfile's width and height
    bi.biWidth = (int)(bi.biWidth * factor); // might be issue w/ floating point
    bi.biHeight = (int)(bi.biHeight * factor);
    
    float yFactor =  (float) bi.biHeight / orgHeight; // **SET THIS TO A MAX NUMBER OF DECIMAL .s
    float xFactor =  (float) bi.biWidth / orgWidth;
       
    bool xIsFloat;      
    bool yIsFloat;


    if ((xFactor - (int)xFactor) > 0)
        xIsFloat = true;
    else
        xIsFloat = false;
        
   if ((yFactor - (int)yFactor) > 0)
        yIsFloat = true;
    else
        yIsFloat = false;
    
    // sometimes we don't reach the factor completely, hence the additional Tolerant
    float yFactorTolerant;
    float xFactorTolerant;
    
    if (xIsFloat)
        yFactorTolerant = yFactor - 0.0001; 
    else
        yFactorTolerant = yFactor; 
        
    if (yIsFloat)
        xFactorTolerant = xFactor - 0.0001;
    else
        xFactorTolerant = xFactor; 

    // determine padding for scanlines with new dimensions ->notice mpl'n by factor
    int padding =  (4 - (bi.biWidth * BTSPXL) % 4) % 4;
    int orgPadding = (4 - (orgWidth * BTSPXL) % 4) % 4;
       
    // modify size of the pixels themselves (in bytes)
    bi.biSizeImage = (bi.biWidth * abs(bi.biHeight) * BTSPXL)
                      + (padding * abs(bi.biHeight)); 

    
    // modify imagefile size
    bf.bfSize = bi.biSizeImage + HDRSZ;
       
    // write outfile's BITMAPFILEHEADER
    fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);

    // write outfile's BITMAPINFOHEADER
    fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
    
    if (factor < 1)
    {
        downscaler(inptr, outptr, padding, orgPadding, orgHeight, orgWidth, bi.biHeight, bi.biWidth);
        return 0;
    }

    // clear image so garbage values don't interfere **THIS IS DUCT TAPE
    if (xIsFloat || yIsFloat)
    {
        for (int i = 0; i < abs(bi.biHeight); i++)
        {
            for (int j = 0; j < bi.biWidth * BTSPXL; j++)   
            {
                fputc(0x00, outptr);
            }
            for (int k = 0; k < padding; k++)
            {
                fputc(0x00, outptr);
            }
        }
    }
    
    // put pointer back to beginning (after headers)
    fseek(outptr, HDRSZ, SEEK_SET);
    
    // iterate over infile's scanlines
    for (int i = 0; i < abs(orgHeight); i++)
    {
        // iterate over pixels in scanline
        for (int j = 0; j < orgWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;
            RGBTRIPLE preExTriple;
                        
            // "switch" for whether or not we are on the final Y repitition
            float yMix = 0;
            float xMix = 0;

            // for readability, we are making a variable for the length of one full line, one row, and one column
            int lineLength = bi.biWidth * BTSPXL + padding;
            int rowSize = ceil(xFactor) * BTSPXL; // number of bytes in a row of a block
            
            // read RGB triple from infile
            fread(&triple, BTSPXL, 1, inptr);
            
            // to check how many lines we have written in the block
            int columnSize = 0;  
            for (float k = 0; k < yFactorTolerant;) // begin the block
            {     
                if (yIsFloat)                   
                {
                    if ((k == 0) && ((yFactor * i) < (ceil(yFactor * i)))) // first row of the block, but not first line of file
                        yMix = (ceil(yFactor * i)) - (yFactor * i);
                        
                    if ((yFactor - k) < 1) // last row of the block.... second one would never happen
                        yMix = (yFactor - k);
                }
                    
                for (float h = 0; h < xFactorTolerant;)
                {
                    RGBTRIPLE newTriple = triple;
                    
                    if ((h == 0) && ((xFactor * j) < (ceil(xFactor * j))))
                        xMix = (ceil(xFactor * j)) - (xFactor * j);
                    
                    else if ((xFactor - h) < 1)
                        xMix = xFactor - h;
                    
                    else
                    {
                        xMix = 1;
                        if (yMix == 0)
                        {
                            fwrite(&newTriple, BTSPXL, 1, outptr); 

                            h += xMix;           
                            xMix = 0;
                             
                            continue;
                        }
                    }

                    fread(&preExTriple, BTSPXL, 1, outptr);
                    fseek(outptr, -BTSPXL, SEEK_CUR);
                        
                    newTriple = modifier(preExTriple, triple, xMix, yMix);
                                       
                    fwrite(&newTriple, BTSPXL, 1, outptr);
                                        
                    h += xMix;           
                    xMix = 0;  
                }
              
                
                // initializing variables to determine where we are (last row of block and/or last block of file-width)
                bool lastSubRow;
                bool lastBlock;
                
                columnSize++;
                
                // to check if this is the last line of the block                
                if ((k + 1) < yFactorTolerant)
                    lastSubRow = false;
                else
                    lastSubRow = true;    
                
                // checking if we are on the last pixel in the input file    
                if ((orgWidth - j) != 1) 
                    lastBlock = false;
                else
                    lastBlock = true;
                    
                
                if (lastBlock == false) // we aren't at the last block
                {
                    if (lastSubRow == false) 
                    {
                        fseek(outptr, lineLength - rowSize, SEEK_CUR); // overlapping last written byte    
                    }
                    else if (lastSubRow == true) 
                    {
                        if (((xFactor * (j+1)) - (int)(xFactor * (j+1))) > 0)
                            fseek(outptr, - (lineLength * (columnSize - 1)) - (BTSPXL), SEEK_CUR); // get ready for a new block
                        else
                            fseek(outptr, - (lineLength * (columnSize - 1)), SEEK_CUR); 
                    }
                }
                // last pixel in row (after last in sub-row, and this is the last repitition of bi.biWidth)
                else if (lastBlock == true) 
                {
                    for (int j = 0; j < padding; j++)
                    {
                        fputc(0x00, outptr);                      
                    }
                     
                    // we are on the last repitition, then go to the next line, and get ready for another repitition
                    if (lastSubRow == false) 
                    {
                        fseek(outptr, lineLength - padding - rowSize, SEEK_CUR);
                    }
                    if (lastSubRow && (((yFactor * (i+1)) - (int)(yFactor * (i+1))) > 0))
                    {
                        fseek(outptr, - lineLength, SEEK_CUR);
                    }
                }
                
                if (yMix == 0)
                    k++;
                else
                    k += yMix;   
                yMix = 0;
            }
        }

        // skip over padding, if any
        fseek(inptr, orgPadding, SEEK_CUR);
    }
    
    // close infile
    fclose(inptr);

    // close outfile
    fclose(outptr);

    // that's all folks
    return 0;
}
void DestructibleHierarchy::breakOffNode(int nodeIdx, hkArray<DestructibleHierarchyCollisionEvent>& collisionEvents)
{
	Node* node = &m_nodes[nodeIdx];

	int immediateParent = node->m_parentIdx;
	HK_ASSERT2(0xad78d9dd, immediateParent != INVALID_NODE_INDEX, "where's the parent?");

	// detach from parent
	Node* immediateParentNode = &m_nodes[immediateParent];
	HK_ON_DEBUG( int initChildCount = immediateParentNode->m_childrenIdx.getSize() );
	for (int c = 0; c < immediateParentNode->m_childrenIdx.getSize(); c++)
	{
		if (immediateParentNode->m_childrenIdx[c] == nodeIdx)
		{
			immediateParentNode->m_childrenIdx.removeAtAndCopy(c);
			break;
		}
	}
	HK_ASSERT2(0xad78ddaa, initChildCount-1 == immediateParentNode->m_childrenIdx.getSize(), "child not detached!" );

	hkTransform accumulatedTransform = immediateParentNode->m_transform;

	// Find parent rigid body..
	int parentIdx = immediateParent;
	Node* parentNode = immediateParentNode;
	while(parentNode->m_body == HK_NULL)
	{
		parentIdx = parentNode->m_parentIdx;
		parentNode = &m_nodes[parentIdx];
		hkTransform tmp; tmp.setMul(parentNode->m_transform, accumulatedTransform);
		accumulatedTransform = tmp;
		HK_ASSERT2(0xad678daa, parentNode, "No parent rigid body found!");
	}

	// Create new body
	hkpRigidBody* newBody;
	{
		hkpShape* shape = buildShape(nodeIdx);
		hkpShape* flatShape = hkFlattenShapeHierarchyUtil::flattenHierarchy(shape);
		shape->removeReference();
		newBody = DestructibleHierarchy::buildRigidBody(flatShape, this, nodeIdx);
		flatShape->removeReference();

		const hkSmallArray< hkpCollisionListener* >& listeners = parentNode->m_body->getCollisionListeners();
		for (int i = 0; i < listeners.getSize(); i++)
		{
			newBody->addCollisionListener(listeners[i]);
		}

	}
	// init velocites for new body
	{
		// reposition the body
		hkTransform parentTransform;
		if (parentNode->m_initialTransformOfHierarchy)
		{
			parentTransform = *parentNode->m_initialTransformOfHierarchy;
		}
		else
		{
			parentTransform = parentNode->m_body->getTransform();
		}
		hkTransform newBodyTransform; newBodyTransform.setMul( parentTransform, accumulatedTransform );
		newBody->setTransform(newBodyTransform);

		// compute velocities
		hkVector4 linVel = parentNode->m_body->getLinearVelocity();
		hkVector4 angVel = parentNode->m_body->getAngularVelocity();
		hkVector4 relCm; relCm.setSub4(newBody->getCenterOfMassInWorld(), parentNode->m_body->getCenterOfMassInWorld());
		hkVector4 extraLin; extraLin.setCross(angVel, relCm);
		linVel.add4(extraLin);
		newBody->setLinearVelocity( linVel );
		newBody->setAngularVelocity( angVel );

	}

	// set newBody  position
	parentNode->m_body->getWorld()->addEntity(newBody);
	newBody->removeReference();
	newBody = HK_NULL;

	// Update shape of parent body
	if (!parentNode->m_body->isFixed())
	{
		hkpShape* shape = buildShape(parentIdx);
		if (shape)
		{
			hkVector4 oldCm = parentNode->m_body->getCenterOfMassInWorld();
			hkpShape* flatShape = hkFlattenShapeHierarchyUtil::flattenHierarchy(shape);
			updateShapeOfRigidBody(flatShape, parentNode->m_body);
			shape->removeReference();
			flatShape->removeReference();

			hkVector4 relCm; relCm.setSub4(parentNode->m_body->getCenterOfMassInWorld(), oldCm);
			hkVector4 extraLin; extraLin.setCross(parentNode->m_body->getAngularVelocity(), relCm);

			hkVector4 linVel; linVel.setAdd4(parentNode->m_body->getLinearVelocity(), extraLin);
			parentNode->m_body->setLinearVelocity(linVel);
		}
		else 
		{
			parentNode->m_body->getWorld()->removeEntity(parentNode->m_body);
			parentNode->m_body->removeReference();
			parentNode->m_body = HK_NULL;
		}
	}
	else // if (!parentNode->m_body->isFixed())
	{

		// if we're breaking off of a fixed shape -- this must be the one fixed mopp shape

		const hkpShape* shape = parentNode->m_body->getCollidable()->getShape();
		HK_ASSERT2(0xad1788dd, shape->getType() == HK_SHAPE_MOPP, "The fixed body must have a mopp.");
		const hkpMoppBvTreeShape* mopp = static_cast<const hkpMoppBvTreeShape*>(shape);

		// Remove shapeKeys from mopp

		HK_ACCESS_CHECK_OBJECT(parentNode->m_body->getWorld(), HK_ACCESS_RW );

		hkArray<hkpShapeKey> brokenOffShapeKeys;
		collectShapeKeys(nodeIdx, brokenOffShapeKeys);

		for (int i = brokenOffShapeKeys.getSize()-1; i >=0; i--)
		{
			if(brokenOffShapeKeys[i] == HK_INVALID_SHAPE_KEY)
			{
				brokenOffShapeKeys.removeAt(i);
			}
			else
			{
				const hkpMoppBvTreeShape* moppShape = static_cast<const hkpMoppBvTreeShape*>( parentNode->m_body->getCollidable()->getShape() );
				removeSubShapeFromDisplay(parentNode->m_body, const_cast<hkpMoppBvTreeShape*>(moppShape), brokenOffShapeKeys[i]);
			}
		}
		hkpRemoveTerminalsMoppModifier modifier(mopp->getMoppCode(), mopp->getShapeCollection(), brokenOffShapeKeys);
		modifier.applyRemoveTerminals( const_cast<hkpMoppCode*>(mopp->getMoppCode()) );

		// disable contact points for the removed shapes..
		hkPointerMap<hkpShapeKey, int> shapeKeyMap;
		shapeKeyMap.reserve(brokenOffShapeKeys.getSize());
		for (int k = 0; k < brokenOffShapeKeys.getSize(); k++)
		{
			shapeKeyMap.insert(brokenOffShapeKeys[k], 0);
		}

		for (int e = 0; e < collisionEvents.getSize(); e++)
		{
			if (collisionEvents[e].m_contactMgr)
			{
				hkpShapeKey key = collisionEvents[e].m_shapeKey;

				hkPointerMap<hkpShapeKey, int>::Iterator it = shapeKeyMap.findKey(key);
				if (shapeKeyMap.isValid(it) && collisionEvents[e].m_body == parentNode->m_body)
				{
					static_cast<hkpDynamicsContactMgr*>(collisionEvents[e].m_contactMgr)->getContactPoint(collisionEvents[e].m_contactPointId)->setDistance(100000.0f);
					collisionEvents.removeAt(e);
					e--;
				}
			}
			else
			{
				collisionEvents.removeAt(e);
				e--;
			}
		}

	}



}
Example #26
0
void OSNacl::handle_event(const pp::InputEvent& p_event) {

	int type = p_event.GetType();
	switch (type) {

	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
	case PP_INPUTEVENT_TYPE_MOUSEUP:
	case PP_INPUTEVENT_TYPE_WHEEL: {

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_BUTTON;
		event.device=0;

		pp::MouseInputEvent mevent(p_event);
		if (type == PP_INPUTEVENT_TYPE_WHEEL) {

			pp::WheelInputEvent wevent(p_event);;
			float ticks = wevent.GetTicks().y();
			if (ticks == 0)
				break; // whut?

			event.mouse_button.pressed = true;
			event.mouse_button.button_index = ticks > 0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN;
			event.mouse_button.doubleclick = false;

		} else {

			event.mouse_button.pressed = (type == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			event.mouse_button.button_index = mouse_button(mevent.GetButton());
			event.mouse_button.doubleclick = (mevent.GetClickCount() % 2) == 0;

			mouse_mask &= ~(1<< (event.mouse_button.button_index - 1));
			mouse_mask |= (event.mouse_button.pressed << (event.mouse_button.button_index - 1));
		};
		pp::Point pos = mevent.GetPosition();
		event.mouse_button.button_mask = mouse_mask;
		event.mouse_button.global_x = pos.x();
		event.mouse_button.x = pos.x();
		event.mouse_button.global_y = pos.y();
		event.mouse_button.y = pos.y();
		event.mouse_button.pointer_index = 0;
		event.mouse_button.mod = modifier(p_event.GetModifiers());
		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_MOUSEMOVE: {

		pp::MouseInputEvent mevent(p_event);
		pp::Point pos = mevent.GetPosition();

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::MOUSE_MOTION;
		event.mouse_motion.pointer_index = 0;
		event.mouse_motion.global_x = pos.x();
		event.mouse_motion.global_y = pos.y();
		event.mouse_motion.x = pos.x();
		event.mouse_motion.y = pos.y();
		event.mouse_motion.button_mask = mouse_mask;
		event.mouse_motion.mod = modifier(p_event.GetModifiers());

		event.mouse_motion.relative_x = pos.x() - mouse_last_x;
		event.mouse_motion.relative_y = pos.y() - mouse_last_y;
		mouse_last_x = pos.x();
		mouse_last_y = pos.y();

		queue_event(event);

	} break;

	case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYDOWN:
	case PP_INPUTEVENT_TYPE_KEYUP: {

		pp::KeyboardInputEvent kevent(p_event);
		bool is_char;
		uint32_t key = godot_key(kevent.GetKeyCode(), is_char);
		if (type != PP_INPUTEVENT_TYPE_KEYUP && is_char) {

			last_scancode = key;
			break;
		};

		InputEvent event;
		event.ID=++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = (type != PP_INPUTEVENT_TYPE_KEYUP);
		event.key.scancode = key;
		event.key.unicode = key;

		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		event.key.mod = modifier(p_event.GetModifiers());
		queue_event(event);
	} break;

	case PP_INPUTEVENT_TYPE_CHAR: {

		pp::KeyboardInputEvent kevent(p_event);
		InputEvent event;
		event.ID = ++event_id;
		event.type = InputEvent::KEY;
		event.key.pressed = true;
		event.key.scancode = last_scancode;
		event.key.unicode = kevent.GetCharacterText().AsString().c_str()[0];
		event.key.mod = modifier(p_event.GetModifiers());
		event.key.echo = p_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT;
		queue_event(event);

	} break;

	/*
	case NPEventType_Minimize: {

		minimized = p_event->u.minimize.value == 1;

	} break;


	case NPEventType_Focus: {

		if (p_event->u.focus.value == 1) {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
		} else {
			main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
		};
	} break;

	*/

	default:
		;
	};
};
    void TestArchiveParabolicBoxDomainPdeModifier()
    {
        // Create a file for archiving
        OutputFileHandler handler("archive", false);
        handler.SetArchiveDirectory();
        std::string archive_filename = handler.GetOutputDirectoryFullPath() + "ParabolicBoxDomainPdeModifier.arch";

        // Separate scope to write the archive
        {
            // Create PDE and boundary condition objects
            MAKE_PTR_ARGS(UniformSourceParabolicPde<2>, p_pde, (-0.1));
            MAKE_PTR_ARGS(ConstBoundaryCondition<2>, p_bc, (1.0));

            // Create a ChasteCuboid on which to base the finite element mesh used to solve the PDE
            ChastePoint<2> lower(-10.0, -10.0);
            ChastePoint<2> upper(10.0, 10.0);
            MAKE_PTR_ARGS(ChasteCuboid<2>, p_cuboid, (lower, upper));

            // Create a PDE modifier and set the name of the dependent variable in the PDE
            std::vector<double> data(10);
            for (unsigned i=0; i<10; i++)
            {
                data[i] = i + 0.45;
            }
            Vec vector = PetscTools::CreateVec(data);
            ParabolicBoxDomainPdeModifier<2> modifier(p_pde, p_bc, false, p_cuboid, 2.0, vector);
            modifier.SetDependentVariableName("averaged quantity");

            // Create an output archive
            std::ofstream ofs(archive_filename.c_str());
            boost::archive::text_oarchive output_arch(ofs);

            // Serialize via pointer
            AbstractCellBasedSimulationModifier<2,2>* const p_modifier = &modifier;
            output_arch << p_modifier;
        }

        // Separate scope to read the archive
        {
            AbstractCellBasedSimulationModifier<2,2>* p_modifier2;

            // Restore the modifier
            std::ifstream ifs(archive_filename.c_str());
            boost::archive::text_iarchive input_arch(ifs);

            input_arch >> p_modifier2;

            // Test that member variables are correct
            TS_ASSERT_EQUALS((static_cast<ParabolicBoxDomainPdeModifier<2>*>(p_modifier2))->rGetDependentVariableName(), "averaged quantity");
            TS_ASSERT_DELTA((static_cast<ParabolicBoxDomainPdeModifier<2>*>(p_modifier2))->GetStepSize(), 2.0, 1e-5);
            TS_ASSERT_EQUALS((static_cast<ParabolicBoxDomainPdeModifier<2>*>(p_modifier2))->AreBcsSetOnBoxBoundary(), true);

            Vec solution = (static_cast<ParabolicBoxDomainPdeModifier<2>*>(p_modifier2))->GetSolution();
            ReplicatableVector solution_repl(solution);

            TS_ASSERT_EQUALS(solution_repl.GetSize(), 10u);
            for (unsigned i=0; i<10; i++)
            {
                TS_ASSERT_DELTA(solution_repl[i], i + 0.45, 1e-6);
            }

            delete p_modifier2;
        }
    }
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode)
{
    if (!parentNode.isValid())
        parentNode = rootQmlItemNode();

    Q_ASSERT(parentNode.isValid());

    QmlItemNode newNode;

    try {
        RewriterTransaction transaction = beginRewriterTransaction();
        if (itemLibraryEntry.typeName().contains('.')) {

            const QString newImportUrl = itemLibraryEntry.requiredImport();

            if (!itemLibraryEntry.requiredImport().isEmpty()) {
                const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
                Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);

                foreach (const Import &import, model()->imports()) {
                    if (import.isLibraryImport()
                            && import.url() == newImport.url()
                            && import.version() == newImport.version()) {
                        // reuse this import
                        newImport = import;
                        break;
                    }
                }

                if (!model()->hasImport(newImport, true, true)) {
                    model()->changeImports(QList<Import>() << newImport, QList<Import>());
                }
            }
        }

        QList<QPair<QString, QVariant> > propertyPairList;
        propertyPairList.append(qMakePair(QString("x"), QVariant(round(position.x(), 4))));
        propertyPairList.append(qMakePair(QString("y"), QVariant(round(position.y(), 4))));

        if (itemLibraryEntry.qml().isEmpty()) {
            foreach (const PropertyContainer &property, itemLibraryEntry.properties())
                propertyPairList.append(qMakePair(property.name(), property.value()));

            newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList);
        } else {
            QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
            inputModel->setFileUrl(model()->fileUrl());
            QPlainTextEdit textEdit;


            textEdit.setPlainText(Utils::FileReader::fetchQrc(itemLibraryEntry.qml()));
            NotIndentingTextEditModifier modifier(&textEdit);

            QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
            rewriterView->setCheckSemanticErrors(false);
            rewriterView->setTextModifier(&modifier);
            inputModel->attachView(rewriterView.data());

            if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
                ModelNode rootModelNode = rewriterView->rootModelNode();
                inputModel->detachView(rewriterView.data());

                rootModelNode.variantProperty("x") = propertyPairList.first().second;
                rootModelNode.variantProperty("y") = propertyPairList.at(1).second;

                ModelMerger merger(this);
                newNode = merger.insertModel(rootModelNode);               
            }
        }

        if (parentNode.hasDefaultProperty()) {
            parentNode.nodeAbstractProperty(parentNode.defaultProperty()).reparentHere(newNode);
        }

        if (!newNode.isValid())
            return newNode;

        QString id;
        int i = 1;
        QString name(itemLibraryEntry.name().toLower());
        //remove forbidden characters
        name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
        do {
            id = name + QString::number(i);
            i++;
        } while (hasId(id)); //If the name already exists count upwards

        newNode.setId(id);

        if (!currentState().isBaseState()) {
            newNode.modelNode().variantProperty("opacity") = 0;
            newNode.setVariantProperty("opacity", 1);
        }

        Q_ASSERT(newNode.isValid());
    }
void InstCvt::initBrig() {
  initBrigBase(sizeof(Brig::BrigInstCvt), Brig::BRIG_KIND_INST_CVT);
  Inst::initBrig();
  modifier().initBrig();
}
void InstSegCvt::initBrig() {
  initBrigBase(sizeof(Brig::BrigInstSegCvt), Brig::BRIG_KIND_INST_SEG_CVT);
  Inst::initBrig();
  brig()->segment = Brig::BRIG_SEGMENT_NONE;
  modifier().initBrig();
}